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);
?
總結
以上是生活随笔為你收集整理的Jquery和PHP Ajax JSON的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oralce中的to_date()函数
- 下一篇: 装修设计费一般多少大概多少钱