Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通用HTTPClient或Ajax类_Javascript - Fatal编程技术网

Javascript 通用HTTPClient或Ajax类

Javascript 通用HTTPClient或Ajax类,javascript,Javascript,下面是我如何进行异步调用的,但是我如何在类中进行异步调用并发送url和Required服务。。。作为参数 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

下面是我如何进行异步调用的,但是我如何在类中进行异步调用并发送url和Required服务。。。作为参数

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);
我希望你期待着这样的事情。你可以用这个,原型就可以了

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();