tags:

views:

96

answers:

2

Hello. I am trying to figure out why my $.getJSON method does not seem to be working but the $.ajax works just fine. First, here is my getJSON call:

$.getJSON("http://localhost:1505/getServiceImageList?callback=loadImagesInSelect", loadImagesInSelect);

You can see I have tried added the callback parameter directly to the query string (also tried it not on string) and I added a reference to the callback method defined in my js file.

Here is the $.ajax call which works just fine:

function getImages() {
            $.ajax({
                type: "GET",
                url: $('#txt_registry_url').val(),
                dataType: "jsonp",
                success:loadImagesInSelect ,
                error:function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(thrownError);
                }

            });
        }

In this example the url pulled from the text box is the same as in the straight call to getJSON. When the method call completes, the successMethod is called and everything processes just fine.

While I am cool with using the later of the two methods, the docs make it seem that the getJSON is the preferred shorthand way of doing things.

Can anyone please explain what I am missing on the shorthand method to make it all work?

Thanks in advance.

A: 

Hello, from what I understand you need to use

$.getJSON("http://localhost:1505/getServiceImageList?callback=?", loadImagesInSelect);

jQuery will take care of giving a name to the callback and then forwarding the call to loadImagesInSelect

I hope this will help Jerome WAGNER

Jerome WAGNER
A: 
$.getJSON("http://localhost:1505/getServiceImageList?data=yes&callback=?", loadImagesInSelect);

function loadImagesInSelect(json) {
   //whatever you want on success
}

then server side with php (note: I added data to the GET query string)

$data = getDataAsJSON($_GET['data']);
echo $_GET['callback'] . '(' . $data . ');';

getJSON needs to see "callback=?"

I would stick with $.ajax

Jonathan Mayhak
thanks that seems to work when I replace my callback method with ?
dotnetgeek