我们正在使用 Sencha Touch 1.1 和 PhoneGap 1.3.0 构建一个应用程序以部署到 iOS。
我们的应用程序发出多个 AJAX 请求来验证用户身份并从服务器检索数据。除了尝试使用无效凭据进行身份验证之外,我们的所有请求均正确执行。
我正在使用 Weinre 调试在 iOS 模拟器中运行的应用程序。 在“网络” Pane 中,请求卡在“待处理”状态,并且在控制台中我收到以下错误:
发生错误:未定义:[未知 lineno]:ReferenceError:找不到变量:请求
达到超时值时会出现此错误。
这是我的 Controller 的代码:
Ext.regController('Login', {
login: function(options)
{
var loader = this.application.viewport.query('#loader')[0];
loader.show();
var string = options.user + ":" + options.pass;
var encodedString = Ext.util.Base64.encode(string) + "==";
Ext.Ajax.defaultHeaders = { Authorization: "Basic " + encodedString};
Ext.Ajax.request({
url: 'http://test.com/login.do',
method: 'POST',
timeout: 5000,
scope: this,
callback: function (options, success, response) {
if (success){
buildingStore.load({
callback: function (){
Ext.redirect('Main/loggedIn');
loader.hide();
}
});
Ext.redirect('Main/loggedIn');
}
else {
alert("failed");
console.log(response.status);
loader.hide();
var loginFailure = new Ext.Panel ({
floating: true,
centered: true,
floating: true,
modal: true,
layout: 'fit',
cls: 'loginError',
html: '<h12>Login was unsuccessful.<br>Please try again.</h12>',
});
loginFailure.show();
}
}
});
Ext.Ajax.on({
requesterror: function(conn, response, options, e){
alert("error");
},
requestexception: function(conn, response, options, e){
alert("exception");
}
});
},
});
以及 Weinre 的屏幕截图:
感谢您的帮助! 凯文
最佳答案
升级到 sencha touch 1.1 修复了此问题。感谢@kev_additct。只是将其放在答案中而不是放在已有的评论中
关于ajax - Sencha Touch AJAX 请求问题 : ReferenceError: Can't find variable: request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9382229/