Ajax 'get' call returns jsonp in order, but callback produces data 'undefined'

I am accessing a cross-domain web service using jQuery a.ajax call from an html page. Although I see jsonp data using firebug, I cannot load it into a variable or even display it (for debugging purposes). Attempts to retrieve data using jsonpCallback, successful and complete functions always result in 'undefined' / null data.

Ultimately, I need to save the data in variables. Any help would be greatly appreciated!

$.ajax({
    data: {
        User: UserValue,
        GUID: GUIDValue
    },
    cache: false,
    dataType: "jsonp", // tried json
    type: "GET",
    crossDomain: true,
    jsonp: false,  // tried true
    jsonpCallback: function (saveData) {
        if (saveData == null) {
            alert("DATA IS UNDEFINED!");  // displays every time
        }
        alert("Success is " + saveData);  // 'Success is undefined'
    },
    url: "http://localhost/NotifMOD/NotifService.svc/GetAllMessages?callback=success?",
    async: false, // tried true
    error: function (XMLHttpRequest, textStatus, errorThrown) {
         console.log(textStatus, errorThrown);
    },
    complete: function (a, b) {
        alert(a); //[object Object]
        alert(b); // parseerror
    }
});
+3
source share
1 answer

In JSONP, you must define your function in your code.

jsonpCallback should be the name of this function, not the function.

. http://api.jquery.com/jQuery.ajax/

:

function receive(saveData) {
    if (saveData == null) {
            alert("DATA IS UNDEFINED!");  // displays every time
    }
    alert("Success is " + saveData);  // 'Success is undefined'
}

$.ajax({
    data: {
        User: UserValue,
        GUID: GUIDValue
    },
    cache: false,
    dataType: "jsonp", // tried json
    type: "GET",
    crossDomain: true,
    jsonp: false,  // tried true
    jsonpCallback: "receive",
    url: "http://localhost/NotifMOD/NotifService.svc/GetAllMessages?callback=receive?",
    async: false, // tried true
    error: function (XMLHttpRequest, textStatus, errorThrown) {
         console.log(textStatus, errorThrown);
    }
});
+3

All Articles