Failed to open remote server file in Titanium

不想你离开。 提交于 2020-01-06 17:58:10

问题


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

来源:https://stackoverflow.com/questions/22094419/failed-to-open-remote-server-file-in-titanium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!