I have read questions about multiple ajax requests, but not about the case in which I have to make 2 or more ajax requests to the same url to get different responses:
function ajaxSub(opc1, value1) {
$.ajax({
type: "GET",
url: $("#urltmp1").val() + "ajax",
async: true,
data: {
o: opc1,
q: value1
},
datatype: "text",
contentType: "application/x-www-form-urlencoded; charset=UTF-8"
})
.done(function (msg) {
if (opc1 == "1" && value1 == "data01") {
$("#field01").val(msg);
}
if (opc1 == "1" && value1 == "data02") {
$("#field02").val(msg);
}
})
.fail(function () {
alert("fail");
});
}
function main01() {
ajaxSub("1", "data01");
ajaxSub("1", "data02");
}
This works if main01() have just one call to ajaxSub(). How can I achieve this? Thanks in advance