java - I'm unable to receive the json object sent from my servlet -
$(document).ready(function() { var path = null; console.log('${pagecontext.request.contextpath}/loadfile'); $.ajax({ datatype: "json", url: '${pagecontext.request.contextpath}/loadfile', success: function(data){ $.each(data,function(index,obj){ console.log(obj.id); alert('inside'); path = obj.path; }); } });
here /loadfile url returns json object , when go url able see json object printed on html page , dont same when access page contains above javascript code
often people don't tell server the browser json string sending interpreted json object.
despite fact datatype:'json'
supposed sort out, not case.
in php
header("content-type: application/json");
asp
response.addheader('content-type', 'application/json');
failing that,
success: function(data){ if (typeof data!='object') data=$.parsejson(data); // create sure it's object
i can't figure out why jquery doesn't prepare response headers, datatype:'json' set can appear application/x-www-form-urlencoded; charset=utf-8
, object doesn't created.
java javascript jquery ajax servlets
No comments:
Post a Comment