get json data by post function of jQuery
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);
});
精彩评论