Questions about receiving and returning values on ajax and php pages! Help !!! Urgent: 1. php page & lt; script & nbsp; type = "text/javascript" & nbsp; src = "jquery-1.3.2.min.js" & gt; & lt; /script & questions about receiving and returning values on ajax and php pages! Help !!! Urgent
This is the 1. php page.
Script
$ (Document). ready (function (){
$ ("Button"). click (function (){
$. Ajax ({
Type: "GET ",
Url: "2.php ",
Data: {id: "123456 "},
DataType: "json ",
Success: function (msg)
{
$ ("# Returncontent" cmd.html (msg );
}
});
});
});
Script
This is the place to display
Button
This is the 2. php page.
Echo & quot; 1111 & quot ";
?>
This will display normally, but if I put 1.php$ ("# returncontent" into .html (msg );
Change to $ ("# returncontent" cmd.html (msg. message );
So I am in 2. how should php write to return to 1.php? I tried echo "{\" message \":". $ _ GET ['id']. "}";, but if I want to write echo "{\" message \":" "; It is always not displayed !! Please advise, newbie !!!
------ Solution --------------------
Echo "{\" message \":" ";
Syntax error.
You can use json_encode () to output text in json format.
$ Data = array (
'Message' =>"
"
);
Echo json_encode ($ data );
------ Solution --------------------
$ Result = array (
'Content' => 'specific content ',
'Message' => 'XX successfully ',
'Statu' => 1,
);
============
JS.
$. Post ('2. php', {id: 123456}, function (data ){
If (data. message) alert (data. message );
If (data. statu = 0) return;
Certificate ('{xxxxx'{.html (data. content );
//... More processing operations
});
------ Solution --------------------
1. when testing in IE series browsers, be sure to clear the cache
2. all possible outputs in php should be placed in a number Group.
Used for output
Echo json_encode ($ array );
Note: Since json_encode only supports UTF-8 encoded Chinese characters, you must pay attention to transcoding when the output contains Chinese characters.
------ Solution --------------------
Script
$ (Document). ready (function (){
$ ("Button"). click (function (){
$. Ajax ({
Type: "GET ",
Url: "2.php? Id = 1234 ",
Success: function (msg)
{
$ ("# Returncontent" cmd.html (msg. message );
$ ("# Returncontent1" cmd.html (msg. message1 );
$ ("# Returncontent2" cmd.html (msg. message2 );
}
});
});
});
Script
This is where the message is to be displayed.
This is where message1 is to be displayed