首頁 >後端開發 >php教程 >AJAX asp.net分頁 ajax php 實作寫入資料庫

AJAX asp.net分頁 ajax php 實作寫入資料庫

WBOY
WBOY原創
2016-07-29 08:40:36910瀏覽

首先需要一個帶輸入表格.

複製程式碼 程式碼如下:










Insert 知識點

知識點










複製程式碼程式碼如下:


/*
* 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=GetXmlHttp=GetXmlHtt ;
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
{
{
// Internet Explorer
try
{
{
// Internet Explorer
try
{
{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)

{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } }

}

}
}
}
}
}
}
}
return xmlHttp;
}


然後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 "輸入成功"; ?> 以上就介紹了AJAX asp.net分頁 ajax php 實作寫入資料庫,包含了AJAX asp.net分頁方面的內容,希望對PHP教學有興趣的朋友有幫助。
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn