Ajax PHP transfer and receive variable implementation ideas and code _php tutorial

Source: Internet
Author: User
So, your jQuery might is something like .....
Copy CodeThe 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 ....
Copy CodeThe 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/326435.html techarticle So, your jQuery might is something like ..... Copy the code as follows: $.ajax ({url: ' query.php ', data: {id:10}, Datatype:json success:function (results) {if (results.msg = = ' suc. .

  • Related Article

    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.