javascript - json parse error: Expected '}' -
i making ajax call
$.ajax({ url: 'url', data: {}, method: 'post', enctype: 'multipart/form-data', datatype: 'json', success: function(data){ // handle success }, error: function(data, textstatus){ //handle error } }); here json response is
{ person: { name: 'john' } as can see, json response not formed. hence error
json parse error: expected '}' in
error: function(data, textstatus){ } how, can ignore parse error , go on executing since have received response.
you can't ignore parser error. parser error, no info has been parsed. prepare data.
if cannot prepare info server-side, improve info source. if cannot , must prepare client side, concatenate } on there, then parse manually (disable jquery parsing), , hope entire scheme doesn't come crumbling downwards when fixes bug later (which inevitable).
from @squint:
don't request json or send json response headers , jquery won't parse it.
what means you're requesting json datatype: 'json'. utilize text instead. more info in jquery docs: http://api.jquery.com/jquery.ajax/
javascript jquery ajax json
No comments:
Post a Comment