I have a JSON call without callback. I want to parse data.
$("button").click(function(){
$.getJSON(
"url",
function(result){
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
});
and HTML
<button>Get JSON data</button>
<div></div>
But there is not any fetched data. What is wrong in my code?
I agree with Sarfraz. It is because it’s a remote based request. One way that I got around this problem in the past was by using a server side file (Such as a .php or .aspx) to load the URL and then performing the getJSON on that locally accessible file.
This is because your server side files can connect to the remote host.
For example you could create a sample test.php file that jquery accesses with this code:
Then just call (relative of course):
Using things like JsonP is good but sometimes they are overkill.
I hope this helps!