Jquery success function not firing using JSONP

前端 未结 5 1638
悲哀的现实
悲哀的现实 2020-11-29 06:26

Been doing some playing call my service which is on a different domain using jQuery. The call to the service is successfully made (my debug point gets tripped), and the cor

5条回答
  •  爱一瞬间的悲伤
    2020-11-29 07:16

    Try

    $.getJSON(urlOnDiffDomain, function(data, textStatus){
        alert('success...');
    });
    

    Works for me, usally. You need to add &callback=? to urlOnDiffDomain, where jQuery automatically replaces the callback used in JSONP.

    The error callback is not triggered, but you can use the global $.ajaxError, like this

    $('.somenode').ajaxError(function(e, xhr, settings, exception) {
        alert('failed');
    });
    

提交回复
热议问题