这个问题我晚上弄了一晚上,然后一直没弄出来,不知是什么问题,今天早上上网一搜,竟然给找到了答案 ,欣喜啊 呵呵 。现在把问题描述一下:
就是我判断一个函数里面的值是否存在,通过jquery ajax调用,但是在调用函数的时候,因为$.ajax()默认是异步的,所以它会在还没有来得及赋值的
情况下,就去执行其他步骤,导致程序一直执行错误,也就是当我保存没有包含已存在的configid时,它也会执行return false,导致保存没有效果,
而包含已存在configid时会弹出已存在消息,这个是正确的.现在贴一段代码:
调用函数:
function save(){
var configID=$("select[name=configId_extentionID]").val();
if(!checkValidInput()){
return false;
}
//test the configid whether it exsited
if(!IsConfigIDExist(configID)){
return false;
}
//window.location=xpcHomeLocation+'PlugInManageAction.do?operation=save';
document.PlugInForm.action=xpcHomeLocation+'PlugInManageAction.do?operation=save';
document.PlugInForm.method='post';
document.PlugInForm.submit();
}
function IsConfigIDExist(configID){
var b=true;
$.ajax({
url:xpcHomeLocation+'PlugInManageAction.do?operation=checkConfigIDExist&configID='+configID,
type:"POST",
async:false,//synchronize:it must have been returned the result ,then execute the program.
dataType:"json",
success:function(result){
if(result.success==false){
alert(result.msg);
b=false;
}
}
})
return b;
}