JQuery plug in jQuery JSONP development ajax call usage considerations

  • 2020-03-29 23:58:44
  • OfStack

JSONP call sample code:


var originImgSrc = 'cnbogs-logo.gif';
$.jsonp({
    url: '',
    data: { imgSrc: originImgSrc },
    callbackParameter: "callback",
    success: function (newImgSrc, textStatus, xOptions) {
        console.log(xOptions.data.imgSrc);
    },
    error: function (xOptions, textStatus) {
    }
});

The first thing to note is the callbackParameter. If there is no special callback function, always write "callback".

The second thing to note is that in the success callback function, you get undefined directly by the variable name originImgSrc, which you need to get by xoptions.data.imgsrc.


Related articles: