Get Request Webassemply
Solved
Qt for WebAssembly
-
Hello
in webassembly i want do a request on my server, if set a static url, it is work, but I need to take host web url.
window.location is not available , Settings does not worksfunction fetchData() { var xhr = new XMLHttpRequest(); var url = window.location.origin + "/data.json"; // Fetch from the same origin xhr.open("GET", url, true); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { resultArea.text = "Response:\n" + xhr.responseText; } else { resultArea.text = "Error fetching data: " + xhr.status; } } }; xhr.send(); }
Do Have you some idea?
Thanks
Pier -
There are two fantistic api in c++
#ifdef __EMSCRIPTEN__ #include <emscripten.h> // Required for calling JavaScript #endif #ifdef __EMSCRIPTEN__ // WebAssembly-specific code emscripten_run_script("console.log('Running in WebAssembly');"); #endif #ifdef __EMSCRIPTEN__ const char* url = emscripten_run_script_string("window.location.href"); qDebug() << "Current Page URL:" << url; #endif
-
P piervalli has marked this topic as solved