search

Home  >  Q&A  >  body text

javascript - A single page executes multiple jsonp ajax requests. How to judge whether one ajax request is completed and then another?

(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) {


                },

            })

        },

    }
仅有的幸福仅有的幸福2709 days ago751

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-30 10:00:11

    promise

    $.ajax(...)
        .then(res => {
            ... 
            return $.ajax()
        })
        .then(....)

    reply
    0
  • Cancelreply