Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Get Request Webassemply
QtWS25 Last Chance

Get Request Webassemply

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
2 Posts 1 Posters 91 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    piervalli
    wrote on 13 Mar 2025, 19:15 last edited by
    #1

    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 works

    function 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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      piervalli
      wrote on 13 Mar 2025, 20:07 last edited by piervalli
      #2

      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
      
      1 Reply Last reply
      0
      • P piervalli has marked this topic as solved on 13 Mar 2025, 20:08

      2/2

      13 Mar 2025, 20:07

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved