我想同时发送AJAX请求。我尝试使用for循环
for(i = 0;i <= 10; i ++){
$.get("http://search.roblox.com/catalog/json?CatalogContext=1&SortType=0&SortAggregation=3&SortCurrency=0&LegendExpanded=true&Category=0", function(r){
var date = new Date();
console.log(date.getTime());
});
}
但是,它们不会同时发送,并且记录的时间之间存在明显差异。我想基本上在彼此的同时发送它们(如果可能的话)。 我想知道是否有任何方法可以做这样的事情?
答案 0 :(得分:-4)
<!DOCTYPE html>
@*!!!!!!!!!! added to routes routes.IgnoreRoute("{resource}.axd/{*pathInfo}");!!!!!!!*@
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<style type="text/css">
body {
width: 300px;
}
</style>
</head>
<body>
<div class="aSpinner" style="display: none;" onclick="">
<img src="~/Content/ajax_busy2.gif" title="Please wait.... Contacting server for action..." />
...Please wait.... Contacting server for action...
</div>
<div id="divMore"></div>
<div>
<script type="text/javascript">
$(".aSpinner").show();
$.when(
$.get("/Main/Index01", function (html01) {
$("#divMore").append(html01);
}),
$.get("/Main/Index02", function (html02) {
$("#divMore").append(html02);
}),
$.get("/Main/Index03")
).then(function () {
// All is ready now, so...
$("#divMore").append("all three call done aynchronously");
});
</script>
</div>
</body>
</html>
ously“);
public class MainController : Controller
{
//
// GET: /Main/
public string Index01()
{
return "index01";
}
public string Index02()
{
return "index02";
}
public string Index03()
{
return "index03";
}