2014-05-09 3 views
0

이 내가 현재 API 호출을 사용하여 티타늄을 만드는 방법의 예입니다 :JQuery와 아약스는 해당 티타늄

var url = "http://www.appcelerator.com"; 
var client = Ti.Network.createHTTPClient({ 
    // function called when the response data is available 
    onload : function(e) { 
     Ti.API.info("Received text: " + this.responseText); 
     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", url); 
// Send the request. 
client.send(); 

말썽이 방법을 수행하여, 나는 오전 온로드 호출에서 개체에 액세스 할 경우에만 수 백 기능.

내가 예를 들어이 작업을 수행 할 수

:이처럼,이 작업을 수행 할 수있을 것 JQuery와 AJAX를 사용

//snippet 
    var someObject; 

    onerror : function(e) { 

     someObject = this.responseText; 

      }, 

//end  

function useObject(someObject){ 

alert(someObject); 


} 

가 : 응답이 수신

$.ajax({ 
      type: "POST", 
      url: 'someurl', 
      data: param = "", 
      contentType: "application/json; charset=utf-8", 
      success: self.useObject, 
      error: errorFunc 
     }); 

일단에 전달 성공 개체.

Jquery를 사용하지 않는다는 가정하에 Titanium에서 어떻게 평형을 수행 할 수 있습니까?

답변

1

나는 완전히 당신이 달성하려고하는 것을 이해하지만, 같은 것을 시도하지 말라 :

var onLoad = function(e) { 
    console.log(this.responseText); 
}; 

var client = Ti.Network.createHTTPClient({ 
    onload: onLoad 
});