ajax php传递和接收变量实现思路及代码

前端之家收集整理的这篇文章主要介绍了ajax php传递和接收变量实现思路及代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

So,your jQuery might be something like.....
<div class="codetitle"><a style="CURSOR: pointer" data="7490" class="copybut" id="copybut7490" onclick="doCopy('code7490')"> 代码如下:

<div class="codebody" id="code7490">
$.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....
<div class="codetitle"><a style="CURSOR: pointer" data="99204" class="copybut" id="copybut99204" onclick="doCopy('code99204')"> 代码如下:
<div class="codebody" id="code99204">
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);
}

原文链接:https://www.f2er.com/ajax/26846.html

猜你在找的Ajax相关文章