Last active
October 10, 2015 01:27
-
-
Save vinothbabu/3610365 to your computer and use it in GitHub Desktop.
Generic HTTPClient or Ajax Class which only creates a single instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var JSONCall = function(url,data, onLoad, onError){ | |
this.url = url; | |
this.data = data; | |
this.onLoad = onLoad; | |
this.onError = onError; | |
}; | |
JSONCall.prototype = { | |
call: function(){ | |
if(typeof JsonClient==='undefined'){ | |
JsonClient = Titanium.Network.createHTTPClient(); | |
} | |
JsonClient.open("POST", this.url); | |
//setting Request Header | |
JsonClient.setRequestHeader("Content-type", "application/json"); | |
JsonClient.send(this.data); | |
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment