I am not a JS guy (can write some basic stuff), I am working on integrating our Payment API with the front end, as part of the process, we want to trigger a timeout in case my back-end Payment API is not responding within a given timeframe. Here is the JS code which interacting with the Payment API.
performAuthorizePaymentRequest: function (payment) {
return new Promise(function (resolve, reject) {
$.ajax({
type: 'POST',
url: encodedContextPath + '/checkout/authorise_order',
data: JSON.stringify(payment),
dataType: 'json',
contentType: 'application/json',
success: resolve,
error: reject,
always: function () {
pageSpinner.end()
},
timeout: 30000 /* call this.session.completePayment() within 30 seconds or the payment is cancelled */
});
});
}
This seems to be working fine, however I have seen the following issue.
- In case m backed API throws any error, the code is still waiting for the timeout.
- Even for success cases, the js is waiting for timeout before showing success message.
Is there a way to handle this? Let me know in case I am doing something wrong here.
Note: This code will only execute of Safari, for other browser this is not available
from handlign timeout with Ajax call
No comments:
Post a Comment