Time delay in AJAX Succcess

success: function(resp) {
   window.location.href = "https://www.paypal.com/cgi-bin/webscr?&cmd=_xclick&business=someemail@gmail.com&currency_code=USD&amount=95&item_name=visaconsultancycontribution";

Redirect is currently immediate. Is there a way to hold it for 5 seconds and then in between a Prompt should come that we are directing you to Paypal. Prompt should come Just beyond the button.


1 Like

I tried using this →

window.location.href = "https://www.paypal.com/cgi-bin/webscr?&c=_xclick&business=email@gmail.com&currency_code=USD&amount=95&item_name=visaconsultancycontribution";
setTimeout(function(){ alert("You will be redirected to Paypal"); }, 5000);

I think that the time is set, but that alert prompt is not appearing.

you have told the alert to show up 5 seconds later, but you havent told the href to delay.

You are right. Please guide me on how can I delay that. A function is needed to envelop the href?

May be something like this.

But the issue is how can we handle two delays simultaneously:

  1. Pop Up delay
  2. Actual URL redirect.

I tried this →

 success: function(resp) {
 window.location.href = "https://www.paypal.com/cgi-bin/webscr?&cmd=_xclick&business=email@gmail.com&currency_code=USD&amount=95&item_name=visaconsultancycontribution";
                    setTimeout(function(){ alert("You will be redirected to Paypal"); }, 5000);
 timeout: 10000,

No success.

Yes… the timeout function.

setTimeout(function(){ WhateverYouPutInHereIsGoing; ToBeDelayed5seconds; }, 5000);

I don’t quite understand your desired order and timing of operations.

Try submitting the form here.

What I want:

  1. The first prompt comes that e are directing to Paypal then
  2. Redirect to Paypal happens.

But this is not happening now.

I think a prompt confirm messagebox would be better than an alert message box. Because it stops script execution you could put the location change inside it and do away with the settimeout altogether.

Messageboxes may not be as elegant as page elements but I think most users are familiar with them.

The flow would be like

  • AJAX returns successfully
  • user sees a type of “continue, yes or no?”
  • the user then has control of both whether or not they continue and when it happens
1 Like

I am very new to AJAX. Can you guide me how can we achieve point#2 and point#3?

Those aren’t AJAX, the code would go inside the success function

success: function(resp) { 
  // do stuff with the response ?
  // confirm / location code 
} , 

It looks like some minor tweaking of the MDN example (eg. your own message and location instead of window open) should work

The page cautions

but a “continue” is not an “undo” so I think as long as you word the messages carefully you should be OK

1 Like

sir before you provided me this solution I built something like this →

No need to fill the full form. Just put email, and then click submit. A modal will appear.