Hi, I was perusing the group looking to help a colleague with a
similar problem.

One thing I noticed here, and maybe this has no bearing at all, was
the difference between the syntax in the first two posts:

jayQuery wrote:

$.getJSON('http://site1:8888/myjson.json?format=json&callback=?', {},
function(data) { alert(data.result); })

Mike Alsup wrote:

$.getJSON('http://site1:8888/myjson.json?format=json&callback=?',
function(data) {
        alert(data.result);

});

Those are different from one another. jayQuery passes an empty set of
braces as second argument to getJSON, whereas Mike's passes the data
function as the 2nd argument. Also, jay's overall wrapper function is
not closed with a semicolon.

Not sure if it has any bearing at all, just noting that one says his
works and the other says his doesn't, but they are different.


On Oct 23, 8:47 am, Mike Alsup <mal...@gmail.com> wrote:
> > the json file named "myjson.json" (I've reduced its contents to its
> > minimum for testing purposes and it validates in JSONLint):
> > {"result": "true"}
>
> > The javascript:
> > $.getJSON('http://site1:8888/myjson.json', {}, function(data) { alert
> > (data.result); })
>
> > I'm testing it in a local server (MAMP), and the code above works as
> > expected.
>
> > The problem is when I place the query that contains the callback (?
> > format=json&callback=?), as I understand correctly, this is the way to
> > get cross domain json:
>
> > $.getJSON('http://site1:8888/myjson.json?format=json&callback=?', {},
> > function(data) { alert(data.result); })
>
> > It doesn't show the alert, either when in my local server or in an
> > outside server.
>
> > By looking at the firebug console/net panel, I can see that the
> > response + json are correct, but the alert simply doesn't happen...
> > All this because of the cross domain query.
>
> > I've tried all the other ways ($.ajax(), $.get(), $.post()) and after
> > adding the callback query nothing happens!
> > I've even tryed adding the "( )" and doing an eval, but nothing...
> > Anything I put inside the function(data) {} is ignored.
>
> Both of these methods work fine for me:
>
> $.getJSON('http://site1:8888/myjson.json?format=json&callback=?',
> function(data) {
>         alert(data.result);
>
> });
>
> $.ajax({
>         url: 'http://site1:8888/myjson.json?format=json',
>         dataType: 'jsonp',
>         success: function(data) {
>                 alert(data.result);
>         }
>
> });

Reply via email to