Questions about receiving and returning values on ajax and php pages!

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.