Callback function not working when using getJSON
This is the code that I use when I write a link in a browser (IE or Mozilla), it works as a (MyFunc ({ "memes": [{ "-source": " http: //www.knall ..... . ), but when I try to run it as an HTML file, I have an error in the status bar.what is the problem ?. Thanks
<head>
<style>img{ height: 100px; float: left; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="images"></div>
<script>$.getJSON("http://tagthe.net/api/?url=http://www.knallgrau.at/en&view=json&callback=MyFunc",function(data){
alert(data);
});
</script>
</body>
a source to share
You should use getScript
instead getJSON
as you are calling the url of a different domain name.
Update:
The following code works fine for me:
<head>
<style>img{ height: 100px; float: left; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="images"></div>
<script>
function MyFunc(data) {
alert(data)
}
$.getScript("http://tagthe.net/api/?url=http://www.knallgrau.at/en&view=json&callback=MyFunc");
</script>
</body>
a source to share
you cannot make ajax calls on other domains
http://en.wikipedia.org/wiki/Same_origin_policy
Also, your url is not a valid url, copy and paste it into the browser and you will see the error http://tagthe.net/api/url=http://www.knallgrau.at/en&view = json & callback = MyFunc
valid url: http://tagthe.net/api/?url=http://www.knallgrau.at/en&view=json&callback=MyFunc
$.getJSON("
http://tagthe.net/api/url=http://www.knallgrau.at/en&view=json&callback=MyFunc",
function(data){
alert(data);
});
a source to share