我有两个按钮,其中一个已经绑定了来自不同站点的 ajax 调用。我需要使用第一个按钮调用 ajax,并且我需要在 ajax 完成后将一些数据附加到结果中。我无权编辑 ajax 函数或现有的 jQuery。我所能做的就是创建一个新函数。所以请不要让我编辑 ajax jQuery 或函数。只是我需要从控制台调用它。是否有任何 jQuery 函数可以知道是否调用了 ajax 以及是否有成功响应。我尝试使用ajaxStart()和ajaxStop()。但不工作。这是我试过的。jQuery('.a').click(function(){ var valuetopass; //Copy Value from input of A jQuery(document).ajaxStart(function(){ console.log('Click Ajax Button'); valuetopass = jQuery('.a_value').val(); }); //Call Ajax jQuery('.b').click(); //Paste Value to the result appended jQuery(document).ajaxStop(function(){ console.log('Appended the result input field(b_value) to the html.'); //Paste the value in new field from ajax. jQuery('.b_value').val(valuetopass); });});<input class="a_value" value="ABC"/><button class="a">Button to initiate ajax</button><button class="b">Button having Ajax</button>在这里,当我们单击按钮时A,它将启动单击按钮B并调用 ajax。之后,结果将在 HTML 中附加一个输入字段,如<input class="b_value"/>. 我需要使用外部 jQuery 函数为此字段添加值。我也试过setTimeout(function(){ jQuery('.b_value').val(valuetopass)},500);但我们不能说 500 毫秒将是所花费的确切时间。有没有可能找到调用并完成的ajax。
1 回答

qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
你可以使用 .ajaxComplete(),像这样使用
$( document ).ajaxComplete(function(event, xhr, settings) {
console.log(xhr.responseText);
});
这里 xhr.responseText 将拥有 jQuery ajax 方法进行的每个 ajax 调用的响应。所以你的响应<input class="b_value"/>可以在这个回调中处理
添加回答
举报
0/150
提交
取消