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

ajax php 實(shí)現(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 知識點(diǎn)
<form name="insertForm">
<label for="question"></label>知識點(diǎn)
<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ù)器獲取提交后的返回?cái)?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 實(shí)現(xiàn)寫入數(shù)據(jù)庫,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 大学英语综合教程1答案| 邓稼先教案设计一等奖优秀教案| 苏教版二年级下册数学| 许薇| 微笑江湖| 章若楠高清壁纸| 秀人网大尺度| 拥抱星星的月亮演员表| 唐人街探案5免费完整观看| 七年级的英语翻译全书| 十里承欢电影版免费播放| deathnote| 假男假女| 情满四合院46集免费播放电视剧| 欢乐的牧童钢琴谱| 遥远的天熊山电影完整版在线观看| 男士血压标准对照表| 我的极品女神 电影| 大红灯笼高高挂剧情介绍| 申请采购的请示范文| xxxxxxxxxxxxx| 天国恩仇| 炊事班的故事演员表| 格子论文| 科洛弗| 小曼哈顿| 少年包青天3演员表| 假如我是一坨屎作文| himym| 邓稼先教学设计一等奖优秀教案| 我的父老乡亲| 美人天下| 灰姑娘电影| 黑帮大佬和我的第365天| be小说| 飞越情海| 服务群众方面整改成效| 人流后饮食| angels of death| 地理填充图册| 韩漫画未删减男同|