javascript - Generic HTTPClient or Ajax Class -



javascript - Generic HTTPClient or Ajax Class -

var url = "https://www.appcelerator.com"; var service = someservicename; var xhr = ti.network.createhttpclient({ onload: function(e) { // this.responsetext holds raw text homecoming of message (used json) // this.responsexml holds returned xml (used soap web services) // this.responsedata holds returned binary info 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);

here how making async calls, how create in class , send url, , requrired service... parameters

var jsoncall = function(url,servic, onload, onerror){ // api url phone 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){ /* response */ }, onerror = function(error){ /* error */ }; // create instance var jsoncall = new jsoncall(url,"servicename", myload, myerror); // phone call jsoncall.call();

i hope expecting this. can utilize this, prototype job.

javascript

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -