Jquery 在这种情况下,如何管理Ajax调用的执行顺序
我有一个页面,在该页面下,客户id从一个页面传递到另一个页面(来回) 我面临的问题是,有时客户id可能未定义或为空 在这种情况下,我希望基于Ajax调用提供客户id 这是我的密码Jquery 在这种情况下,如何管理Ajax调用的执行顺序,jquery,ajax,Jquery,Ajax,我有一个页面,在该页面下,客户id从一个页面传递到另一个页面(来回) 我面临的问题是,有时客户id可能未定义或为空 在这种情况下,我希望基于Ajax调用提供客户id 这是我的密码 var cust_id = getParameterByName('cust_id'); $(document).on('click', '#saveaddress', function() { cust_id = '' if(cust_id==''||cust_id=='undefined'||c
var cust_id = getParameterByName('cust_id');
$(document).on('click', '#saveaddress', function() {
cust_id = ''
if(cust_id==''||cust_id=='undefined'||cust_id=='')
{
}
if(somecondition)
{
$.ajax({
type: 'GET',
url: url+'/OMS/oms1/chdsavenewaddresslabel?mobile_number='+phonenumber+'&location='+location+'&cust_id='+cust_id+'&address1='+address1+'&address2='+address2+'&landmark='+landmark+'&locality='+locality+'&area='+area+'&city='+city+'&state='+state,
jsonpCallback: 'jsonCallback',
dataType: 'jsonp',
jsonp: false,
success: function(response) {
},
error: function(e) {
alert('Error inside Fill form request');
}
});
}
else
{
alert('Please correct the Error');
}
});
function fetchCustomerId(uuid)
{
$.ajax({
type: 'GET',
url: url+'/OMS/oms1/fetchcustomerId?uuid='+uuid,
jsonpCallback: 'jsonCallback',
cache: true,
dataType: 'jsonp',
jsonp: false,
success: function (responsesss) {
var res = responsesss;
var cust_id = res.Id;
},
error: function (e) {
}
});
return cust_id;
}
我面临的问题是这两个Ajax调用混淆了
请告诉我如何独立执行每个Ajax调用查看jquery的承诺文档: 这里有一个将两个ajax调用链接在一起的示例。您可能需要重写一点函数,但这会让您对需要执行的操作有一个很好的了解
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) )
.then( myFunc, myFailure );
为什么没有一个调用
fetchCustomerId
的$(document).ready()
函数,其次,为什么第一个函数映射到document.onclick事件?这难道不意味着只要你点击鼠标,这个功能就会启动吗?