我只是在学习 JavaScript 对象并且有一个问题/问题。我有以下代码/ js 对象:
更改:这是完整的代码 - 这是一个 Appcelerator Titanium 项目!:
spike.xhr = spike.xhr || {};
spike.xhr.init = function() {
this.severResponse = '';
this.xhrMethod = 'GET';
}
spike.xhr.isOnline = function() {
if( Titanium.Network.online ) {
return true;
} else {
return false;
}
}
spike.xhr.notOnline = function() {
var alertDialog = Titanium.UI.createAlertDialog({
title: CONFIG.PROJECT_SHORT,
message: 'You do not have an online connect. Please connect...',
buttonNames: ['Continue'],
cancel: 0
});
alertDialog.show();
}
spike.xhr.connect = function( url ) {
if( spike.xhr.isOnline() ) {
spike.xhr.clients = Ti.Network.createHTTPClient();
spike.xhr.clients.onload = function() {
if (spike.xhr.clients.status != 200 && spike.xhr.clients.status != 201) {
var alertDialog = Titanium.UI.createAlertDialog({
title: CONFIG.PROJECT_SHORT,
message: 'We are sorry, but we have received an status error!',
buttonNames: ['Continue'],
cancel: 0
});
alertDialog.show();
return false;
}
this.serverResponse = this.responseText;
}
spike.xhr.clients.onerror = function(e) {
Ti.API.log( 'ERROR: ' + e.status + ': ' + e.statusText + ' - ' + e.error );
}
spike.xhr.clients.open( this.xhrMethod, url );
spike.xhr.clients.send();
} else {
spike.xhr.notOnline();
}
}
spike.xhr.basicAuthentication = function( username, password ) {
authstr = 'Basic ' +Titanium.Utils.base64encode( username+':'+ password);
spike.xhr.client.setRequestHeader( 'Authorization', authstr );
}
spike.xhr.setMethod = function( type ) {
this.xhrMethod = type;
}
spike.xhr.response = function() {
return this.serverResponse;
}
如果我现在运行:
spike.xhr.connect( 'http://mydomain' );
theResponse = spike.xhr.response();
我得到<null>
回报!- 为什么我不"This is a Test!"
回来或更好的问题:我必须改变什么才能"This is a Test!"
回来?