Php 我可以在jQuery.ajax中的CodeIgniter中调用多个路由吗?
我在CodeIgniter中做了一些类似的事情-Php 我可以在jQuery.ajax中的CodeIgniter中调用多个路由吗?,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我在CodeIgniter中做了一些类似的事情- $('#addSomeData').click(function({ $.ajax({ type: "POST", url: "singleroute", data: $("#theform").serialize(), success: function(data) { $('#tableID').load('viewpage #tableID');
$('#addSomeData').click(function({
$.ajax({
type: "POST",
url: "singleroute",
data: $("#theform").serialize(),
success: function(data) {
$('#tableID').load('viewpage #tableID');
}
});
});
通常,我会在config\routes.php
中放置一个路由。像下面这样-
$routes['singleroute'] = 'myclass/mymethod';
使用上面的代码,一切正常。但是,我想一按按钮就触发多条路线。实际上,我想在五个不同的表中输入一些默认值。我知道一个简单的方法,就是我可以在
mymethod
中为不同的表插入多个insert查询。现在,我的问题是-我可以在一个触发器中调用多个url吗?您可以尝试这样的方法来同时发送多个异步请求:
$.when(
$.ajax("singleroute/task1"),
$.ajax("singleroute/task2")
).then(successCallback, failureCallback);
然后,所有请求完成后,successCallback
将启动,如果任何一个请求失败,failureCallback
将启动。当打开时,阅读有关的更多信息
代码点火器路径:
$routes['singleroute/(:any)'] = "myclass/mymethod/$1";
类方法(mymethod):
没有ajax在提供的url上发布值要将数据发布到多个url,则需要多个ajax请求
public function mymethod($task)
{
// Depending on the $task do something specific
}