Jquery和PHP Ajax JSON

无缓存,无错版
$.ajax({
type: "GET",
url: "index.php",
cache: false,
data: "con=Add&act=_search&key=" + key+"&id="+id,
dataType:"json",
success: function(msg){
bindGroupList(msg);
}
});

//绑定
function bindGroupList(result)
{
var eles = document.forms['theForm'].elements;
eles['group_id'].length = 1;
for (i = 0; i < result.content.length; i++)
{
var opt = document.createElement('OPTION');
opt.value = result.content[i].id;
opt.text = result.content[i].name;
eles['group_id'].options.add(opt);
}
}

会缓存
$.getJSON("?con=Add&act=_search&key=" + key+"&id="+id, function(data){
//bindGroupList(data)
});

=====php make_json_result=======
/**
* 创建一个JSON格式的数据
*
* @access public
* @param string $content
* @param integer $error
* @param string $message
* @param array $append
* @return void
*/
function make_json_response($content = '', $error = "0", $message = '', $append = array()) {
$res = array(
'error' => $error,
'message' => $message,
'content' => $content
);
if (!empty($append)) {
foreach ($append AS $key => $val) {
$res[$key] = $val;
}
}
$val = json_encode($res);

exit($val);
}

/**
*
*
* @access public
* @param
* @return void
*/
function make_json_result($content, $message = '', $append = array()) {
make_json_response($content, 0, $message, $append);
}

return make_json_result($list);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值