0

New to this. I am thinking to display load percentage while making an ajax request. It is actually for a WordPress query. I am curious if there is any parameter similar like below success: function(response) {

may be like : success: function(response, value) { ?

Also looking for any reference documentation if any.

thanks

GeekyOwl
  • 69
  • 6
  • 2
    I'm not sure what you're asking, but the documentation is here: https://api.jquery.com/jquery.ajax – Rory McCrossan Mar 18 '20 at 14:04
  • @RoryMcCrossan thank you. Sorry, I may sound stupid don't know how it works. the success parameter has a function in it and it has a response parameter( not sure where that gets in).. https://praison.com/2017/04/ajax-progress-bar/ in this example they use "value" in it. not sure where that comes aswell – GeekyOwl Mar 18 '20 at 14:07
  • 1
    The function is called internally by jQuery when the AJAX request completes. The first argument to that function, named `value` in the example in your link and `response` in the one in your question holds the contents of that response from the server. – Rory McCrossan Mar 18 '20 at 14:09
  • @RoryMcCrossan so inside that function `value.percent` or `response.percent` is valid for any kind of ajax request? – GeekyOwl Mar 18 '20 at 14:11
  • 1
    No not at all. It completely depends on what content the server responds with. Every endpoint will be different. If you're asking how to display a load percentage using an AJAX request then it depends on what you are uploading and how your server is configured to respond to the request – Rory McCrossan Mar 18 '20 at 14:11
  • @RoryMcCrossan oh okay thanks. Is there any reference or preferred method to know how much percentage is loaded for an ajax request? – GeekyOwl Mar 18 '20 at 14:13
  • 1
    For uploading binary data, such as a file, then [see this answer](https://stackoverflow.com/a/15410637/519413). If you want to do this for a long running action on your server then you'll need to use another method. AJAX polling is one way, although I would advise against this and suggest websockets instead, however you will need to create the code to determine how far through the process your logic is manually. – Rory McCrossan Mar 18 '20 at 14:14
  • @RoryMcCrossan okay thank you very much for clearing my doubts. I will be very happy to mark it as an answer if could drop it as an answer below. – GeekyOwl Mar 18 '20 at 14:17

0 Answers0