problem in ajaxSucess

Asked

Viewed 45 times

0

Hello, I’m having a hard time executing a script after an ajax call.

What I’ve done so far?

Well, I will explain: I have a button with 2 actions, however, I need one action to occur before the other, the two are not together.

I already got the script, but there’s a mistake, every time there is this ajax request, the script executes the amount of requests that have been made, I mean, it’s like having an accountant.

Where I need help?

I need that with each request made, there is no such event ('counter'), that it perform only once, regardless of how many requests were made!

$(document).ajaxSuccess(function(event, xhr, settings) {
  if (settings.url === "somefile.php") {
    alert('hi');
  }
});
  • That code $(document).ajaxSuccess() runs only once or appears in repeating parts of the code?

  • So this code only has one time, but each time that my url is run it does something, that is, if I click a button twice, in the first it will run the script once, now in the second time it will run the same script twice, and so on.

  • ajaxSuccess is to intercept ALL Ajax requests from the page. Is that really what you want? Show the code where you make the request, I think that’s where you should work.

  • That’s right, let’s say like this, any request there is, I want to check the url, if it’s x url, then I’ll run something. The problem is that it starts running x times the script from the requests made successfully. I want to run only the last one.

  • Is Ajax being added repeated somewhere in your code? And so is the ajax itself that is called over and over and not wrong with the .ajaxSuccess.

  • See what happens, I put the script to accept 2 different url... https://snag.gy/oN1W7a

  • Hmm that image confirms what I’m thinking. There’s one more post each time. Without seeing your code it’s hard to help more.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.