如果我使用Ajax发送请求,这个请求需要很长时间.....如果我想发送anther请求我该怎么办?
当前行为第二个请求(我做)等到第一个请求得到响应.
注意: 我想在整个应用程序上执行此行为(任何新请求立即执行而不是等待旧的首先完成)我的应用程序使用(Ajax + PHP + jQuery + Symfony)
假设这是第一个请求需要很长时间:
$.ajax
({
type: "GET",
url: url1,
success: function (html)
{
// do some thing
}
});
Run Code Online (Sandbox Code Playgroud)
在任何时候我都希望这个请求执行并终止第一个请求.
$.ajax
({
type: "POST",
url: url,
success: function (html)
{
// do some thing else
}
});
Run Code Online (Sandbox Code Playgroud)
var xhrReq;
xhrReq = $.ajax(...);
// then if you want to stop the rqest and exit use :
xhrReq.abort();
Run Code Online (Sandbox Code Playgroud) 如何使用jQuery多次加载test.html .
function loadScreen()
{
$('#result').load('test.html');
}
Run Code Online (Sandbox Code Playgroud)
main.html中
<div id='result'></div>
<input type="button" value="click me" onclick="loadScreen()">
Run Code Online (Sandbox Code Playgroud)
的test.html
<body>
<p>
testing
</p>
</body>
Run Code Online (Sandbox Code Playgroud)
现在的情况
当我点击按钮点击我.它将在main.html测试中加载一次show
我想做的事
当我单击按钮两次它将显示时,我该怎么办呢
testing
testing
Run Code Online (Sandbox Code Playgroud)
和不同的div id
第一次按钮单击显示测试 <div id="result1">testing</div>
第二次按钮单击显示测试 <div id="result2">testing</div>
它会在id处追加增量1.
我有这个代码,我想发送两个值,因为你看到我已经在数据领导我想发送ledit2与ledit
$('.ledit').click(function() {
var ledit = $(this).attr("id");
var ledit2 = $('.valu').val();
$.ajax({
url: 'edit.php',
data: 'ledit=' + ledit,
// here i want send ledit2
success: function(data) {
$('.edito').html('dddddddddd');
}
});
});?
Run Code Online (Sandbox Code Playgroud) 当我使用 JQuery 一起发送两个 ajax 请求时.. 响应一起
$.ajax
({
type: "POST",
url: 'ajax.php'
});
$.ajax
({
type: "POST",
url: 'ajax2.php'
});
Run Code Online (Sandbox Code Playgroud)
ajax.php , ajax2.php 是两个文件,包含一个虚拟的 for 循环大约需要 5 秒。
POST localhost/ajax.php 200 OK 4.77s
POST localhost/ajax.php 200 OK 4.37s
这里每个请求大约需要 5 秒才能执行.....
当我在 symfony 做同样的例子时,我得到了不同的结果
$.ajax
({
type: "POST",
url: 'module/action1'
});
$.ajax
({
type: "POST",
url: 'module/action2'
});
Run Code Online (Sandbox Code Playgroud)
action1 , action2 是两个动作,只包含一个虚拟的 for 循环大约需要 5 秒。
POST localhost/web/frontend_dev.php/module/action1 200 OK 4.47s
POST localhost/web/frontend_dev.php/module/action2 200 OK 9.87s
请注意, …