ajax 'GET' call returns jsonp okay but callback produces 'undefined' data

北慕城南 提交于 2019-12-05 22:43:53

In JSONP you must define your function in your code.

jsonpCallback must be the name of this function, not a function.

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

You do it like this :

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);
    }
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!