2012-07-18 74 views
0

我调用两个AJAX功能和URL是相同ajax.php和功能都在同一时间,现在的问题是被解雇的是如何显示到正确的领域如何过滤Ajax响应

的反应是什么我在做

调用功能1和2

为前。在一个我得到史蒂夫,jobes并在两个拉胡尔,潘卡

我想说明的史蒂夫,jobes和拉胡尔,潘卡在不同的领域,但

什么我得到的是,各占4名在这两个字段中显示现在我需要过滤这些名称如何做到这一点?

+2

发布您的代码! – coolguy 2012-07-18 10:57:28

+0

你能告诉我一些代码吗? – sofl 2012-07-18 10:59:18

+0

使用querystring变量并检查你的ajax.php文件中的变量。 – 2012-07-18 10:59:26

回答

1

将回调与ajax调用一起传递,该调用将标识要填充的正确位置。

对于如: 的第一个要求,你会发送一个回调 cb1('field1', ajaxresponse);

和第二请求你将发送一个回调 cb2('field2', ajaxresponse);

然后你就可以使用响应根据自己的需要来填充正确的字段

jQuery中

function cb1(field, response){ 
// do your stuff here like innerHTML or value 
$('#'+field).html(response); 
$('#'+field).val(response); 
} 

function cb2(field, response){ 
// do your stuff here like innerHTML or value or anything as per your logic depending on response 
$('#'+field).html(response); 
$('#'+field).val(response); 
} 

在JavaScript

function cb1(field, response){ 
    document.getElementById(field).innerHTML = response; 
} 

function cb2(field, response){ 
    document.getElementById(field).innerHTML = response; 
} 

,或者如果函数做相同的工作,然后传递参数或初始请求参数去功能使其WUD填充正确的位置

+0

可以发布其他细节,如果你可以指导你是否使用'jQuery'或'javascript' – swapnilsarwe 2012-07-18 11:14:20