四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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處理界面,負責跟服務(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)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 防冲撞应急处置预案| 抗日电影免费| 黑暗女监日本电影完整版叫什么| 瑞斯·伊凡斯| 罗中立的《父亲》详案| gaysex双巨巴| 97热| 3片| 李越昕蕾| 王盼盼| 高等学校毕业生登记表自我鉴定怎么写| 永远是少年电影免费观看| 中央6套| 珠帘玉幕上映时间| 《剪窗花》童谣| 朱丽安·摩尔| 江南好简谱| 黄色网址在线免费播放| 甄子丹100部经典电影| 蒋昌义| 我和大姨子| 大叔呀你到底想干嘛| 蹲着吐一地呕吐视频| 洛嘉| 明日花绮罗| 监禁逃亡2| 必修二英语课本电子版| 冬日舞蹈教程完整版| 电影《神童》| 武林外史电视剧免费观看| 仓皇一夜| 贴身保镖完整电影| 侦探们的镇魂歌国语版在线观看| 黑衣人| 肖红| 怎么做发射器| 轮回乐队| 日本电影姐姐| 电影《大突围》免费观看完整版| 性欲满载| 二次元美女放屁|