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>

      

+2


a source to share


4 answers


You don't define MyFunc anywhere in your code. You would rather put ?

in the URL instead of an arbitrary name, and jQuery will replace it with the generated callback name.



+4


a source


Eureka! It doesn't work with the latest version ... you must be using jquery 1.3.1 not newer ...



0


a source


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>

      

-1


a source


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);
    });

      

-1


a source







All Articles