Home > Backend Development > PHP Tutorial > Implementation ideas and code for passing and receiving variables in ajax php_PHP tutorial

Implementation ideas and code for passing and receiving variables in ajax php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:13:40
Original
945 people have browsed it

So, your jQuery might be something like.....

复制代码 代码如下:

$.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....
复制代码 代码如下:

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);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/326435.htmlTechArticleSo, your jQuery might be something like..... 复制代码 代码如下: $.ajax({ url: 'query.php', data: {id:10}, datatype: json success: function(results) { if (results.msg == 'suc...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template