jquery ajax 删除回调,Jquery - Ajax - 回调函数?(Jquery - Ajax - callback function?)

Jquery - Ajax - 回调函数?(Jquery - Ajax - callback function?)

我使用$ .get请求获取一些数据,然后将其存储在cookie中。 当用户单击按钮时,将运行get请求。 然后,他们将跟随到另一页面的链接,并且存储到cookie的数据被提取并显示在新页面上。

不幸的是,有些人在点击时非常活跃,获取请求会运行,但在有时间完成之前会转到下一页。 这显然会导致错误。 所以我想编写一些代码来禁用链接到下一页,直到get请求完成,但我不知道如何。

这就是我现在所拥有的一切。

$.get(url, function(d) {

cp = $('textarea#txt_quote', d).html();

z_cookie.set(topic_id, current_posts, '1');

});

I am using a $.get request to get some data and am then storing it in a cookie. The get request is ran when a user clicks a button. They would then follow a link to another page and the data stored to the cookie is extracted and displayed on the new page.

Unfortunately some people are rather vigorous with their clicking, the get request runs but the go to the next page before it's had time to complete. This obviously causes an error. So I am wanting to code something which will disable the link to the next page until the get request has finished, but I don't know how.

This is all I have at the moment.

$.get(url, function(d) {

cp = $('textarea#txt_quote', d).html();

z_cookie.set(topic_id, current_posts, '1');

});

原文:https://stackoverflow.com/questions/3277566

更新时间:2019-11-13 21:46

最满意答案

您可以通过处理其click事件来禁用链接,如下所示:

var link = $('selector to find tag');

link.click(function() { return false; });

$.get(url, function(d) {

cp = $('textarea#txt_quote', d).html();

z_cookie.set(topic_id, current_posts, '1');

link.unbind('click');

});

如果需要,可以在click处理程序中设置变量,如果已设置,则在AJAX请求完成后导航到该页面,如下所示:

location.href = link.attr('href');

You can disable the link by handling its click event, like this:

var link = $('selector to find tag');

link.click(function() { return false; });

$.get(url, function(d) {

cp = $('textarea#txt_quote', d).html();

z_cookie.set(topic_id, current_posts, '1');

link.unbind('click');

});

If you want to, you can set a variable in the click handler, and, if it's been set, navigate to the page after the AJAX request finishes, like this:

location.href = link.attr('href');

相关问答

在http错误上调用错误回调,但是如果JSON解析响应失败 。 如果响应代码是200,那么可能会发生这种情况,但您仍然被引发至错误回调。 Error callback is called on http errors, but also if JSON parsing on the response fails. This is what's probably happening if response code is 200 but you still are thrown to error c

...

您不能为主函数返回false,因为它已在ajax调用完成时处理完毕。 你需要使用回调。 function check_options(callback) {

var voucher_code = $('#voucher_code').val();

$.post(baseURL + "ajax.php", {

tool: "vouchers",

action: "check_voucher",

voucher_code: voucher

...

fadeIn()并不是真正的返回承诺的函数,但它有一个可以使用的回调函数: $.ajax({

url: url,

}).done(function (){

$('#listings').fadeIn(800, function(){

$('#loading').fadeOut(800);

});

});

fadeIn() is not really the sort of function that returns a promise, but it do

...

这是我使用的Jquery版本搞砸了。 那是CDN。 凯文B - 非常感谢。真的很有帮助。 感谢所有其他人,我也为他们调查过。 你们很棒,我喜欢这个社区。 我希望我能帮助回来...... 后来伙计们。 :) It was the version I was using of Jquery that messed things up. the CDN that is. Kevin B - thank you much .that really helped. Thank you to all the

...

您可以通过处理其click事件来禁用链接,如下所示: var link = $('selector to find tag');

link.click(function() { return false; });

$.get(url, function(d) {

cp = $('textarea#txt_quote', d).html();

z_cookie.set(topic_id, current_posts, '1');

link.unbind('cli

...

只需使用: function getData() {

$.ajax({

url : 'example.com',

type: 'GET',

success : handleData

})

}

success属性仅需要引用函数,并将数据作为参数传递给该函数。 您可以访问handleData函数,因为handleData被声明的方式。 JavaScript将在运行前解析函数声明的代码,因此您可以在实际声明之前的代码中使用该函数。 这被称

...

是的,我们可以传递多个参数,它取决于被调用的事件及其定义方式。 成功是为Ajax调用自动完成功能的回调。 您应该在jQuery网站上阅读这些函数的文档。 jQuery API Doc yes we can pass multiple parameters, It depends upon event which is being called & how it defined. Success is callback for Ajax being called for autocomplete f

...

尝试更改您的请求以使用$ .ajax而不是$ .post,因为$ .post无声地失败。 $.ajax({

type: "POST",

url: "login.php",

dataType: 'text',

data: { username: username, password: password },

success: function(data) {

if(data == 'Incorrect password'){

$('#login_

...

使用“dataType”而不是“数据类型”。 Javascript是区分大小写的,因此,jQuery忽略了你的设置。 请注意,如果您在响应中正确设置标题(我假设您将其作为文本发回),那么jQuery可以自动检测数据类型。 Use "dataType" not "datatype". Javascript is case-sensitive, therefore, jQuery is ignoring your setting. Note that jQuery can auto-detect th

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值