Ajaxphp implementation of passing and receiving variables and code _ PHP Tutorial

Source: Internet
Author: User
Ajaxphp transmits and receives variable implementation ideas and code. So, yourjQuerymightbesomethinglike ..... copy the code as follows: $. ajax ({url: query. php, data: {id: 10}, datatype: jsonsuccess: function (results) {if (results. msgsuc So, your jQuery might be something like .....

The code is as follows:


$. Ajax ({
Url: 'query. php ',
Data: {id: 10 },
Datatype: json
Success: function (results ){
If (results. msg = 'success '){
For (var I in data ){
$ ('# Content'). append (
'Id = '+ results. data [I]. id + ', description =' + results. data [I]. description + ', msrp =' + results. data [I]. msrp
);
}
} Else {
$ ('# Content'). append (results. msg );
}
}
});


And your php ....

The code is as follows:


If (isset ($ _ GET ['id']) {
$ SQL = "SELECT id, description, msrp FROM tbl WHERE id = '{$ _ GET ['id']}'";
$ Return = array ();
If ($ result = mysql_query ($ SQL )){
If (mysql_num_rows ($ result )){
$ Return ['MSG '] = 'success ';
While ($ row = mysql_fetch_assoc ($ result )){
$ Return ['data'] [] = $ row;
}
} Else {
$ Return ['MSG '] = 'no results found ';
} Else {
$ Return ['MSG '] = 'query failed ';
}
Header ("Content-type: application/json ");
Echo json_encode ($ result );
}

Http://www.bkjia.com/PHPjc/326435.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326435.htmlTechArticleSo, your jQuery might be something like ..... the code is as follows: $. ajax ({url: 'query. php ', data: {id: 10}, datatype: json success: function (results) {if (results. msg = 'suc...

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.