async-ajax call not working as expected

后端 未结 2 1183
死守一世寂寞
死守一世寂寞 2021-01-27 01:20

Setup:

I am doing an ajax-jsonp call, which is working fine. The callback function of this changes value of a variable, \"myVaraible\". Just after the c

2条回答
  •  盖世英雄少女心
    2021-01-27 02:09

    I believe there's no reason you cannot do

        function myfunction() {
            return $.ajax({
                url: myURL,
                dataType: "jsonp",
                jsonp : "jsonp",
                jsonpCallback: "jsonpCallbackFn"
            });
        }
    

    and then

    ...
    $("#preview_button").mouseover(function() {
        myfunction().done(function(){
            alert("after myfunction");
        });
    });
    

    jQuery appears to do a bunch of magic behind the scenes to normalize jsonp requests to act somewhat like jquery ajax requests, so I think this is fine. Let me know otherwise.

提交回复
热议问题