ajax php传递和接收变量实现思路及代码
ajax php传递和接收变量实现思路及代码
发布时间:2016-12-29 来源:查字典编辑
摘要:So,yourjQuerymightbesomethinglike.....复制代码代码如下:$.ajax({url:'query.php'...

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

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新php教程学习
热门php教程学习
编程开发子分类