$(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 is the url which returns the json object , when I go to this url I am able to see the JSON object printed on the html page , however I dont get the same when I access the page which contains the above javascript code
Often people don’t tell their server to the the browser that the JSON string they are sending is to be interpreted as a json object.
Despite the fact that
dataType:'json'is supposed to sort it out, it is not always the case.in PHP
ASP
Failing that,
I can’t figure out why jQuery doesn’t fix it but the response headers, even with dataType:’json’ set can appear as
application/x-www-form-urlencoded; charset=UTF-8and the object doesn’t get created.