2014-03-04 74 views
0

我在鈦新希望顯示遠程服務器的數據我的目標是傳遞對象值的for循環鈦

Object 
todo: Array[2] 
    0: Object 
    todo: "Khaleeq Raza" 
    __proto__: Object 
    1: Object 
    todo: "Ateeq Raza" 
    __proto__: Object 
length: 2 
__proto__: Array[0] 
__proto__: Object 
    VM90:10 

我的代碼是在鈦合金打造行,並希望把數據

var client = new XMLHttpRequest(); 
    client.open("GET", "http://192.168.1.109/read_todo_list.php", true); 
    client.send(); 
    client.onreadystatechange = function(){ 

    if (client.readyState==4 && client.status==200) 
     { 

      json = JSON.stringify(client.response); 
     var get=JSON.parse(json); 

     for(var i=0; i<get.length; i++){ 

     var row = Ti.UI.createTableViewRow({ 
      title: get[i].todo, 
      hasChild : true, 
      });  
      dataArray.push(row);     
     } 

     $.tableView.setData(dataArray); 

     } 

    }; 

,但我沒有得到任何展示什麼都能b題請幫忙

+0

您已經發布了三次相同的問題.. –

回答

1

有鈦沒有XMLHttpRequest,這裏是一個簡單的方法,讓您的數據(假設正確的服務器configurat離子和無認證)。

var client = Ti.Network.createHTTPClient({ 
    // function called when the response data is available 
    onload : function(e) { 
     Ti.API.info("Received json: " + this.responseText); 
     // Parse JSON 
     var object = JSON.parse(this.responseText); 
     // Get the array 
     var todo = object.todo; 
     // Create table rows 
     var dataArray = []; 
     for(var i=0; i<todo.length; i++){ 
      var row = Ti.UI.createTableViewRow({ 
       title: todo[i].todo, 
       hasChild : true, 
       });  
       dataArray.push(row);     
     } 
     $.tableView.setData(dataArray); 

     alert('success'); 
    }, 
    // function called when an error occurs, including a timeout 
    onerror : function(e) { 
     Ti.API.debug(e.error); 
     alert('error'); 
    }, 
    timeout : 5000 // in milliseconds 
}); 
// Prepare the connection. 
client.open("GET","http://192.168.1.109/read_todo_list.php"); 
// Send the request. 
client.send(); 
+0

感謝您的回覆,但這是創建問題並正常使用XMLHttpRequest正如我所回答的。你說XMLHttp不應該在Titanium中使用,雖然這是行得通的。 – Attarisoft

+0

請給我一個關於鈦購物車的建議。我有Codiegniter應用程序。我想開發像鈦一樣的是這是可能的合金設計HTML等請與謝謝 – Attarisoft

+0

建議您是對的我的代碼是隻在PC瀏覽器中運行,而不是在andriod應用程序。但有一個錯誤:加載資源失敗:請求標頭字段X-Titanium-Id不被Access-Control-Allow-Headers – Attarisoft