Monaca Onsen UI Discord Chat Github Repo

XMLHttpRequest() , Why does it not work..?

  • Hi All,
    I’m building my first app in the Monaca IDE. I want to include an external db, but i go step by step.

    I use an example from w3schools, see below.

    It works fine with a local text file (that is: works in the IDE preview, not in the debugger).

    It doens’t work when i copy the file to a website and change the URL accordingly to:

    var url = “”;

    The app (in browser and in debugger) does not see the file. But i can see the file in my browser.

    What to do…?


    <div id=“id01”></div>

    var xmlhttp = new XMLHttpRequest();
    var url = “myTutorial.txt”;

    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    var myArr = JSON.parse(xmlhttp.responseText);
    };“GET”, url, true);

    function myFunction(arr) {
    var out = “”;
    var i;
    for(i = 0; i < arr.length; i++) {
    out += ‘<a href="’ + arr[i].url + ‘">’ +
    arr[i].display + ‘</a><br>’;
    document.getElementById(“id01”).innerHTML = out;

  • i did see the post on the Cordova Whitelist, but is says: By default, new apps are configured to allow access to any site.

    Maybe it’s not so…

  • No, it is true. In the XML config it says: <access origin="*"/> already.