Jquery jsonp response error - Callback was not called

前端 未结 3 821
难免孤独
难免孤独 2021-02-09 07:34

I\'m trying to get some information from a different domain, the domain allows only jsonp call - others get rejected. How can I get the content instead of execution? Because I g

3条回答
  •  情书的邮戳
    2021-02-09 08:03

    The jsonpCallback parameter is used for specifying the name of the function in the JSONP response, not the name of the function in your code. You can likely remove this; jQuery will handle this automatically on your behalf.

    Instead, you're looking for the success parameter (to retrieve the response data). For example:

    $.ajax({
        url: url,
        crossDomain: true,
        type: "POST",
        data: {key: key},
        contentType: "application/json; charset=utf-8;",
        async: false,
        dataType: 'jsonp',
        success: function(data){
            console.log('callback success');
            console.log(data);
        }
        error: function(xhr, status, error) {
            console.log(status + '; ' + error);
        }
    });
    

    You can also likely remove the other JSONP-releated parameters, which were set to jQuery defaults. See jQuery.ajax for more information.

提交回复
热议问题