就像这样:
function as(){
jQuery.ajax({
url:'#springUrl("/a/abc.htm")',
data:{"verifyCode":code},
type:"post",
async:false,
dataType:"json",
success:function(reg){
if(!reg.isTrue){
jQuery("#iscode").val(reg.isTrue);
alert("验证码错误");
//这里进行终止后面的运行
}else{
jQuery("#iscode").val("");
}
}
})
}
function abcd(){}
这里的顺序执行我用过 return ; 不行 跳转也不行 抛异常也不行,那位大佬有高招,指点一下小弟吧
return false; 试试
位置不对,在回掉中return无效
function as() {
var ok = false;//////////////////////////////
jQuery.ajax({
url: '#springUrl("/a/abc.htm")',
data: { "verifyCode": code },
type: "post",
async: false,
dataType: "json",
success: function (reg) {
if (!reg.isTrue) {
jQuery("#iscode").val(reg.isTrue);
alert("验证码错误");
//这里进行终止后面的运行
} else {
jQuery("#iscode").val("");
ok = true;//////////////////////////////
}
}
})
if (!ok) return;//////////////////////////////
//.............其他代码
}
http://tech.mclarian.com/a/570
return 在回掉中是无效的第一知道,谢谢
要利用回调函数的特性,在即将执行回掉函数时控制
function as(callback){
jQuery.ajax({
url:'#springUrl("/a/abc.htm")',
data:{"verifyCode":code},
type:"post",
async:false,
dataType:"json",
success:function(reg){
if(!reg.isTrue){
jQuery("#iscode").val(reg.isTrue);
alert("验证码错误");
if(callback){
//这里进行终止后面的运行
callback();
}
}else{
jQuery("#iscode").val("");
}
}
}) ;
}
as(function(){
//验证通过后做的事
});
function as() {
var ok = false;//////////////////////////////
jQuery.ajax({
url: '#springUrl("/a/abc.htm")',
data: { "verifyCode": code },
type: "post",
async: false,
dataType: "json",
success: function (reg) {
if (!reg.isTrue) {
jQuery("#iscode").val(reg.isTrue);
alert("验证码错误");
//这里进行终止后面的运行
} else {
jQuery("#iscode").val("");
ok = true;//////////////////////////////
a()
}
}
})
}
function a(){
//其他代码
}
你不就是else 才执行么,摘出来