The basic format of Ajax
var info= "";
Creating objects
var xhr=new xmlhttprequest ();
Handling Return Values
Xhr.onreadystatechange = function () {
Determine if loading is complete
if (xhr.readystate = = 4) {
if (xhr.responsetext== "success") {
Location.href= "index.php";
}else{
Alert ("Login" +xhr.responsetext);
}
}
}
Initiating a request
info= "uid=" +uid+ "&pwd=" +PWD;
Get Pass Value
Xhr.open ("Get", "php/login_php.php?") +info);
Post Pass Value
Xhr.open ("Post", "php/login_php.php");
Get Value Header text
Xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
Send data
Xhr.send (info);
String conversion Issues
Converts a two-dimensional array that is queried in the data to a string
Querying the database
$sql = "SELECT * from Fruit";
Execute SQL statement
$ret = $db->query ($sql);
Convert the result to a two-dimensional array
$SPARR = $ret-Fetch_all ();
Convert a two-dimensional array to a string
$str = "";
foreach ($spArr as $v) {
Traverse two-dimensional array, get the one-dimensional array $v, divide the one-dimensional array with Inplode, the result is added to itself, and each one-dimensional array is divided by ^
$str. =implode (",", $v). " ^";
}
Remove the excess ^
Echo substr ($str, 0,-1);
Convert a string to a two-dimensional array
Splitting a string into a one-dimensional array with split and delimiter ^
var temp=str.split ("^");
var arr=[];
Loop to add data from a one-dimensional array to an array
for (Var i=0;i<temp.length;i++) {
Arr[i]=temp[i].split (",");
Console.log (arr);
}
The use of value-passing in Ajax
Get the value of the PHP page when it is finished processing
var str = Xhr.responsetext;
Show (str);
Define a parameter to accept the value passed over
function Tshow (str) {}
Basic knowledge of Ajax