开发者

get json data by post function of jQuery

开发者 https://www.devze.com 2023-04-03 06:29 出处:网络
I wanna to use post function of jQuery to send data to php code,the php code echo json. $array = array(

I wanna to use post function of jQuery to send data to php code,the php code echo json.

$array = array(
           'error_no' => 0;
           'error' => 'error number 0'
              );
echo (json_encode($array));

that is my php code,now how sh开发者_如何转开发ould I get post somethings to this page and access error_no element in javascript var???


Add this before echo, so jQuery knows that this is JSON:

header('Content-Type: application/json');

And then in javascript:

$.post('/the/url.php', post_data, function(json) {
    alert(json.error_no);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消