javascript - A single page executes multiple jsonp ajax requests. How to judge whether one ajax request is completed and then another?
仅有的幸福
仅有的幸福 2017-06-30 09:58:11
0
1
769

(Multiple jsonp requests at the same time will report an error)

a();
b();

For example, it is judged that a has been executed before executing b;

code show as below:

    function Page() {

        this.init();
    }

    Page.prototype = {

        init: function () {
            this.a();
            this.b();
   
        },

        ajaxDataCrossDomain: function (config) {
            var _this = this;
            var result;

            $.ajax({
                type: "GET",
                cache: false,
                async: false,
                url: "",
                data: data,
                dataType: "jsonp",
                jsonp: 'callbackparam',
                success: function (data) {
                    // 在这里的返回值也无法指定给 result
                }
            })

        },


        a: function () {
            var _this = this;
            var result;

            _this.ajaxDataCrossDomain({
                "url": "a.php",
                "mydata": {

                },
                "mysuccess": function (data) {


                },
                
            })

        },

        b: function () {
            var _this = this;
            var result;

            _this.ajaxDataCrossDomain({
                "url": "b.php",
                "mydata": {

                },
                "mysuccess": function (data) {


                },

            })

        },

    }
仅有的幸福
仅有的幸福

reply all(1)
我想大声告诉你

promise

$.ajax(...)
    .then(res => {
        ... 
        return $.ajax()
    })
    .then(....)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template