Failed to open remote server file in Titanium

2019-09-06 15:12发布

问题:

I want to get remote data from server but this is giving error that connection not execution.

And in Console of Chrome browser shows.

Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the    requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access.

XMLHttpRequest cannot load http://domeain.com/json.txt. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access. 

my code is

  function getTodoList (){
    var sendit = Ti.Network.createHTTPClient();
             sendit.open('GET', 'http://domain.com/json.txt');  
             sendit.onload = function(){
        var json = JSON.parse(this.responseText);
        var json = json.todo;
        //if the database is empty show an alert
        if(json.length == 0){
            $.tableView.headerTitle = "The database row is empty";
        }
          dataArray = [];
          for( var i=0; i<json.length; i++)
        {
            var row = Ti.UI.createTableViewRow({
                title: json[i].todo,
                hasChild : true,
            });     
            dataArray.push(row);                
        }

            $.tableView.setData(dataArray);

         };
         sendit.onerror = function(){
                Ti.API.debug(e.error);
                alert('There was an error during the conexion');
         };
         sendit.setTimeout(10000); // 10 sec for timeout

            sendit.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            sendit.setRequestHeader("Access-Control-Allow-Origin", "*");

         sendit.send();
    }

when I give local file like sendit.open('GET', 'json.txt'); json.txt is in my asset folder. Then Its working fine. But I want to get data from Remote Server. How can fix this problem please reply with thanks