简体   繁体   中英

Client/Server operation detection in NodeJS

I would like to have a spinner appear when a form has been submitted and then be replaced by a checkmark to indicate the operation has been completed. I already have JQuery detect when the button has been pressed and make the spinner appear like so:

$('.scrape').on('click', function(){
    $('.spinner').removeClass('hidden');
}) 

How can I have the client/server side detect that the operation has been completed? An AJAX call wouldn't work because the POST request has already been made, right? Note: I am working with the express framework. I'm not rendering anything because it's all on the same page.

Thanks!

Each time you make a request to your server, you should get a response from the server. Receiving a response with a non-error HTTP status means your operation succeeded.

"How can I have the client/server side detect that the operation has been completed?" You mean client. The client ultimately controls what is displayed on the screen, so the client needs to know when it's time for the checkmark. (So I don't care that the server is a NodeJS process using express.)

"An AJAX call wouldn't work because the POST request has already been made, right?" But you must have an handler somewhere for the completion of the request. You haven't said whether you're doing this by $.ajax or vanilla javascript or something else, but whatever you're doing, you just need to add something to that handler so that it adds the checkbox. If you want a more specific answer, feel free to share some more code :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM