2010-09-15 211 views
0

我有一个函数,它执行一些task.inside函数,我有一个ajax调用。如果从ajaxcall获得的响应为真,则该函数应该继续执行其余的任务。否则它应该停止在该点本身。 但上面说的事情没有发生,而是函数独立于ajax调用执行。 请帮我在这ajax函数内呼叫

function f1(id) 
{ 
var test= id 
var url="[email protected]"=+id; 
var ajax=new Ajaxrequest(url,validatecallback); 
ajax.doGet(); 
if(id==true){ 
return; 
} 
........(some code which has to carried out after the ajax call) 
} 
function validatecallback 
{ 
this function gets the response for the above mentioned ajaxcall 
we are setting a global variable(i.e id) here so that we can use that we can retrieve that in function f1 
} 
+0

可能重复[如何从Ajax调用返回响应?](http://stackoverflow.com/questions/14220321/how-to-return-the-响应从-AN-Ajax的呼叫) – Bergi 2014-10-28 14:46:28

回答

0

功能“F1”有一个名为“ID”的正式参数;这是它将在语句“if(id == true)”中测试的变量。尽管也有一个名为“id”的全局变量,并且回调函数将访问并修改它,但它是一个不同的变量。对其进行修改不会影响f1中的测试。