How to pass parameters to an ajax object and reinitiate a request

each ajax is defined as an object because there are more ajax queries in the page and $. When (), is used. For example,

var a1 = $.post({
        url : "/report/A/rank/1",
        data: p1,
        contentType:"application/json;charset=UTF-8",
        dataType : "json",
        success : function(data, textStatus, jqXHR) {}
    });
var a2 = $.post({
        url : "/report/A/rank/2",
        data: p1,
        contentType:"application/json;charset=UTF-8",
        dataType : "json",
        success : function(data, textStatus, jqXHR) {}
    });
$.when(a1, a2).done(function(r1, r2) {
//
});

now, due to some other requirements, I want to dynamically reload a1Maga2 and $.when (a1Magina2), and change the incoming parameter to p2.

alternative: encapsulate the code of the three objects into a function for processing. However, as there are already many ajax on the page and are encapsulated by function, if you encapsulate the code again on this basis, it will affect the readability of the code. Is there a simple way to call it?

Mar.09,2021

Let p1 release p2 first, and then execute a1Magneaa2 recover.resume. If p1 wants to restore the default, re-assign the value to p1 in the callback of when.

Menu