如何设置javascript ajax完成下一行执行 [英] how to set javascript ajax complete next line execute

查看:73
本文介绍了如何设置javascript ajax完成下一行执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面





< asp:Button ID =btnSaverunat =serverText =SaveOnClick =btnSave_ClickOnClientClick =return checkContent(); />



函数checkContent()

{

error = CheckReportNameExist();

if(error ==''){

}

}



函数CheckReportNameExist( ){

$ .ajax({

类型:POST,

url:'url',

contentType:application / json; charset = utf-8,

dataType:json,

asyn:true,

data :'',

beforeSend:function(){

},

成功:函数成功(数据){

errorMsg ='检查错误'

},

失败:功能(响应){},

完成:function(){}

});

返回errorMsg;

}







我的问题



如何ajax完成然后错误检查

使用ajax执行不完整然后下一行代码执行

如何解决这个问题问题

请帮帮我

my page


<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" OnClientClick="return checkContent();" />

function checkContent()
{
error=CheckReportNameExist();
if(error==''){
}
}

function CheckReportNameExist() {
$.ajax({
type: "POST",
url: 'url',
contentType: "application/json; charset=utf-8",
dataType: "json",
asyn:true,
data: '',
beforeSend: function () {
},
success: function Success(data) {
errorMsg='check error'
},
failure: function (response) { },
complete: function () { }
});
return errorMsg;
}



my question

how to ajax complete then error check
am using ajax execute not complete then next line code execute
how to solve this issue
please help me

推荐答案

.ajax({

类型:POST,
url:'url',

contentType:application / json; charset = utf-8,

dataType:json,

asyn:true,

数据:'',

beforeSend:function(){

},

成功:函数成功(数据){

errorMsg ='check error'

},

失败:功能(响应){},

完成:function(){}

});

返回errorMsg;

}







我的问题



如何ajax完成然后错误检查

我使用ajax执行不完成然后下一行代码执行

如何解决这个问题

请帮帮我
.ajax({
type: "POST",
url: 'url',
contentType: "application/json; charset=utf-8",
dataType: "json",
asyn:true,
data: '',
beforeSend: function () {
},
success: function Success(data) {
errorMsg='check error'
},
failure: function (response) { },
complete: function () { }
});
return errorMsg;
}



my question

how to ajax complete then error check
am using ajax execute not complete then next line code execute
how to solve this issue
please help me


那是因为你有设置 asyn:true



请参阅 - jQuery.ajax() [ ^ ]



如果你把它设置为false,那么所有其他事件都会得到持有人回来。当Ajax请求完成时,其他所有内容都会跟随。你可以将它设置为false,如果你想让你的执行同步。



否则你可以为成功块定义一个回调函数,如上所述此处 [ ^ ]并在回调函数本身内执行所有其他操作。
That is because, you have settings asyn:true.

Refer - jQuery.ajax()[^]

If you set it to false, then all other events would get holder back. When Ajax request completes, everything else would follow. You can set it to false, if you want to make your execution synchronous.

Otherwise you can define one callback function for Success Block as described here[^] and do all other things inside the callback function itself.


这篇关于如何设置javascript ajax完成下一行执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆