2012-01-16 2 views
0
여기
var url = "https://www.appcelerator.com"; 
var service = someservicename; 
var xhr = Ti.Network.createHTTPClient({ 
    onload: function(e) { 
     // this.responseText holds the raw text return of the message (used for JSON) 
     // this.responseXML holds any returned XML (used for SOAP web services) 
     // this.responseData holds any returned binary data 
     Ti.API.debug(this.responseText); 
     alert('success'); 
    }, 
    onerror: function(e) { 
     Ti.API.debug(e.error); 
     alert('error'); 
    }, 
    timeout:5000 
}); 

xhr.open("post", url); 
xhr.send(someservicename); 

입니다,하지만 어떻게 내가 매개 변수일반 HttpClient를 또는 아약스 클래스

답변

1
var JSONCall = function(url,servic, onLoad, onError){ 
    // API Url to call 
    this.url = url; 
    this.service = service; 
}; 
JSONCall.prototype = { 
    call: function(){ 
     var JsonClient = Titanium.Network.createHTTPClient(); 
     JsonClient.open("POST", this.url); 
     //setting Request Header 
     JsonClient.setRequestHeader("Content-type", "application/json"); 
     JsonClient.send(service);  
     JsonClient.onload = this.onLoad; 
     JsonClient.onerror = this.onError; 

    } 
}; 

// create callbacks 
var onLoad = function(response){ /* do something with response */ }, 
    onError = function(error){ /* do something with error */ }; 
// create instance 
var jsonCall = new JSONCall(url,"servicename", myLoad, myError); 
// do a call 
jsonCall.call(); 
로 ... 수업 시간에 그것을 확인하고 URL 및 requrired 서비스를 보낼 것입니다

여러분이 이와 같은 것을 기대하시기 바랍니다. 이것을 사용하면 프로토 타입 작업을 수행 할 수 있습니다.