Skip to content
Advertisement

Multiple xmlhttprequestes not sending data to back-end

I’m new to xmlhttprequests, so please bear with me. I am trying to make a program that records the users key press and send it to server to save it to a .txt file, but it is not working. The problem is from the JavaScript side it is not sending the data to the server side. Is it not allowed to send multiple requests to the same server address? Where did I go wrong? I have added comments through out my code to help understand better.

JavaScript:

JavaScript

JavaScript

Advertisement

Answer

Just quickly looking at your JS code, the following line:

JavaScript

… will only send data if the keylog.sending flag is false and the “W” key was previously pressed (any other keys pressed will have no effect and hence, no data will be sent).

You may also want to modify your “sending” code to match that show in the official documentation at: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#example_post

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement