如何调用多个URL从一个按钮,在jQuery的阿贾克斯? [英] How to call more than one url from one button in jQuery ajax?
本文介绍了如何调用多个URL从一个按钮,在jQuery的阿贾克斯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能调用两个URL通过jQuery的一个按钮。例如,我想补充的评论之一,也是。我怎能重新present他们?
$。阿贾克斯({
// URL:AJAX / releaseBackEnd.php',
网址:'批/ 2-释放tmp.php,
键入:POST,
异步:假的,
数据:{FID:ABC},
数据类型:XML,
错误:函数(){
警报('错误加载XML文档);
},
成功:功能(数据){
//检查错误
警报(成功);
。变量$错误= $(数据).find('错误')文本();
如果($错误!=0)
{
消息框(错误,$错误);
返回;
}
}
});
解决方案
您不能让一个Ajax请求的URL 2同步/在同一个电话,你需要分别调用它们作为两个不同的 $。阿贾克斯()
电话。
您可以使它成为一个功能,例如:
函数doAJAX(URL){
$阿贾克斯({
网址:网址,
键入:POST,
异步:假的,
数据:{FID:ABC},
数据类型:XML,
错误:函数(){
警报('错误加载XML文档);
},
成功:功能(数据){
//检查错误
警报(成功);
。变量$错误= $(数据).find('错误')文本();
如果($错误!=0)
{
消息框(错误,$错误);
}
}
});
}
doAJAX(AJAX / releaseBackEnd.php');
doAJAX('批次/ 2-释放tmp.php');
Is it possible to call two urls through a button in jQuery. For example, I want to add the commented one as well. How shall I represent them?
$.ajax({
// url: 'ajax/releaseBackEnd.php',
url: 'batch/2-release-tmp.php',
type: 'POST',
async: false,
data: {"fId":"abc"},
dataType: 'xml',
error: function(){
alert('Error loading XML document');
},
success: function(data){
//check error
alert("success");
var $error=$(data).find('error').text();
if($error!="0")
{
messageBox("Error",$error);
return;
}
}
});
解决方案
You can't make an AJAX request to 2 URLs simultaneously/in the same call, you'll need to call them separately as 2 different $.ajax()
calls.
You could make it a function for example:
function doAJAX(url) {
$.ajax({
url: url,
type: 'POST',
async: false,
data: {"fId":"abc"},
dataType: 'xml',
error: function(){
alert('Error loading XML document');
},
success: function(data){
//check error
alert("success");
var $error=$(data).find('error').text();
if($error!="0")
{
messageBox("Error",$error);
}
}
});
}
doAJAX('ajax/releaseBackEnd.php');
doAJAX('batch/2-release-tmp.php');
这篇关于如何调用多个URL从一个按钮,在jQuery的阿贾克斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文