First you need a table with input.
Copy the Code code as follows:
Insert Knowledge points
Knowledge points
Answer
Copy CodeThe code is as follows:
/*
* 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;
}
Then the PHP processing interface, responsible for exchanging data with the server
Copy the Code code as follows:
/*
* 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 ', ' none ')");
Mysql_close ($con);
echo "Input Success";
?>
The above describes the Ajax ASP. Ajax PHP implementation to write to the database, including the Ajax ASP content, I hope the PHP tutorial interested in a friend helpful.