How do you ensure an XMLHttpRequest() has received its full response before continuing?

I’m looping XMLHttpRequests and for each response I’m pushing it to an array. I use async/await to try to ensure that I only return my array of responses once all of the responses are recieved. For some reason, with no error, this method is not working and I am not getting the full response array.… Read More How do you ensure an XMLHttpRequest() has received its full response before continuing?

fetch() just doesn't send JSON object

I send JSON object using fetch() this way: async testPost(){ const url = ‘https://untitled-0clyb6aowq2u.runkit.sh’; var payload = { "test" : 1 }; const settings = { method: ‘POST’, headers: { Accept: ‘application/json’, ‘Content-Type’: ‘application/json’, body: JSON.stringify(payload) } }; try { const resp = await fetch(url, settings); const data = await resp.json(); if(data.ok != 1){ console.log(‘FATAL… Read More fetch() just doesn't send JSON object

C# – Can't get this seemingly simple web request working

I have the following powershell Web-Request that works correctly for sending a command to a PTZ camera: Invoke-WebRequest -UseBasicParsing -Uri "http://192.168.111.75/ajaxcom" ` -Method "POST" ` -Headers @{ "Accept"="application/json, text/javascript, */*; q=0.01" "Accept-Encoding"="gzip, deflate" "Accept-Language"="en-US,en;q=0.9" "DNT"="1" "Origin"="http://192.168.111.75" "X-Requested-With"="XMLHttpRequest" } ` -ContentType "application/x-www-form-urlencoded; charset=UTF-8" ` -Body "szCmd=encodedStringHere" I’m trying to recreate this in C# but I can’t… Read More C# – Can't get this seemingly simple web request working

How to separate XMLHttpRequest from the main function for better visbility/testibility (without Promises / asnyc/await )

Imagine this function: function myMainFunction() { doSomeInitialStuff(); // more stuff.. var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == XMLHttpRequest.DONE) { // Now that we know we received the result, we can do the heavy lifting here if (xhr.status == 200) { console.log("ready 200"); let result = JSON.parse(xhr.responseText); doStuff(result); // and… Read More How to separate XMLHttpRequest from the main function for better visbility/testibility (without Promises / asnyc/await )

Query parameters are lost from POST request (nodeJS & Express)

I’m trying for the first time to make a JavaScript client and nodeJS server with Express communicate using REST API. For some reason, any parameter I give in xhttp.send is lost when arriving the back-end. In the client side I have the following function: function changeStatus(station) { var xhttp = new XMLHttpRequest(); xhttp.open("POST", "/api", false);… Read More Query parameters are lost from POST request (nodeJS & Express)

Why xmlhttprequest response is in html code

For some reason when I am sending an http request using xmlhttp the answer that I’m getting is in a html form function HttpRequest(method, url, username, password) { const xhr = new XMLHttpRequest(); let received_data; xhr.onreadystatechange = () => { if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responsejson); if (xhr.responseText == "access granted")… Read More Why xmlhttprequest response is in html code