一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ajax php 實現(xiàn)寫入數(shù)據(jù)庫

首先需要一個帶輸入表格.
復(fù)制代碼 代碼如下:
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="submit.js" language="Javascript"></script>
</head>
<body>
Insert 知識點
<form name="insertForm">
<label for="question"></label>知識點
<input name="question" type="text"/>
<br/><br/>
<label for="answer"> 答案</label>
<input name="answer" type="text"/>
<br/>
<br/>
<input name="confirm" value="添加" type="button" onclick="getValue();">
</form>
</body>
</html>

需要js來處理提交數(shù)據(jù)到服務(wù)器上以及從服務(wù)器獲取提交后的返回數(shù)據(jù). submit.js代碼如:
復(fù)制代碼 代碼如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
var xmlHttp;
function getValue(){
alert("getvaluel");
var question =document.insertForm.question.value;
// alert(question);
var answer = document.insertForm.answer.value;
// alert(answer);
submit(question,answer);
};
function submit(question,answer){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
xmlHttp.onreadystatechange =function(){
if(xmlHttp.readyState ==4){
alert(xmlHttp.responseText);
}
};
var url = "insert1.php";
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
xmlHttp.send("question="+question+"&answer="+answer);

}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// InterNET Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

然后php處理界面,負(fù)責(zé)跟服務(wù)器交換數(shù)據(jù)
復(fù)制代碼 代碼如下:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//echo $_POST["question"];
//echo $_POST["answer"];
$q =$_POST['question'];
$a = $_POST['answer'];
//$q='qq';
//$a="a";
$con = mysql_connect("localhost","joe","123");
if (!$con)
{
//die('Could not connect: ' . mysql_error());
echo 'Could not connect: ' . mysql_error();
}
mysql_select_db("joe",$con);
mysql_query("INSERT INTO message VALUES ('$q', '$a', '無')");
mysql_close($con);
echo "輸入成功";
?>

php技術(shù)ajax php 實現(xiàn)寫入數(shù)據(jù)庫,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: wwwxxxx欧美| 国产床戏无遮挡免费观看网站 | 国产精品高清免费网站 | 免费网站看黄 | 日韩美女性行为免费视频 | 国产区更新 | 美女福利视频一区 | 国产a v高清一区二区三区 | 日本高清色视影www日本 | 国产精品视频成人 | 国产盗摄精品一区二区三区 | 四虎社区| 激情六月天婷婷 | 久久久久久麻豆 | 加勒比伊人 | 亚洲伊人精品综合在合线 | 国产高清乱理论片在线看 | caoporn97人人做人人爱最新 | 久久永久免费 | 国产一区 在线视频 | 狠狠做五月深爱婷婷天天综合 | 好吊色青青草 | 成人福利在线免费观看 | 色老板最新 | 韩国一大片a毛片 | 五月婷婷俺来也 | 欧美人体极品大胆露私 | 亚洲a视频在线 | 91精品麻豆| 日本在线观看永久免费网站 | 在线视频综合网 | 日韩中文字幕精品一区在线 | 色亚洲视频 | 四虎在线精品免费高清在线 | 黄在线观看www免费看 | 日韩经典欧美一区二区三区 | 久久久网 | 伊人9999| 久久精品九九 | 91视频站 | 特黄aaaaa日本大片免费看 |