php - jQuery stopping after parseJSON -
$.get('api/dosomething.php',data,function(responsetext){ alert(responsetext); var response = jquery.parsejson(responsetext); alert(response);
the first alert says: object (object)
however, next alert never executed.
uncaught syntaxerror: unexpected token ) file.php:1 4 uncaught syntaxerror: unexpected token o
php:
$result = array('id' => $db->lastinsertid()); header('content-type: application/json'); echo json_encode($result);
your php script tells browser serving json (content-type: application/json
). $.get automatically detects , converts fetched json data valid javascript object.
$.get('api/dosomething.php',data,function(data) { alert(data.id); });
http://api.jquery.com/jquery.ajax/#data-types:
the type of data you're expecting server. if none specified, jquery try infer based on mime type of response
Comments
Post a Comment