Sencha touch 2 sencha touch2登录示例
我需要一个跨域用户登录请求实例,请帮助我,谢谢 我的代码Sencha touch 2 sencha touch2登录示例,sencha-touch-2,Sencha Touch 2,我需要一个跨域用户登录请求实例,请帮助我,谢谢 我的代码 我的问题是,我没有收到服务器返回的值,我错了?Hi@jesse你可以尝试这样的跨域操作 Ext.Ajax.request({ url: 'your_url_path', timeout: 90000, params: { withCredentials: true, useDefaultXhrHeader: false,
我的问题是,我没有收到服务器返回的值,我错了?Hi@jesse你可以尝试这样的跨域操作
Ext.Ajax.request({
url: 'your_url_path',
timeout: 90000,
params: {
withCredentials: true,
useDefaultXhrHeader: false,
username:'13881901678',
password:'111111',
},
success: function(response, o) {
if(response != '') {
alert('1')
}
},
failure: function(response, o) {
alert('2')
}
})
对于跨域,您需要使用凭据放置:true
和使用defaultxhrheader:false
我希望能帮助你。你可以试试这个
Ext.Ajax.request({
method:'GET',
contentType:'application/json; charset=utf-8',
dataType:'json',
url:'http://........Login',
disableCaching: false,
withCredentials: true,
useDefaultXhrHeader: false,
callbackKey: 'callback',
params: {
EmailId:Ext.getCmp('usernametwoway').getValue(),
Password:Ext.getCmp('loginpasswordtwoway').getValue(),
},
success:function(response)
{
console.log(response);
var res = response.responseText;
var jsonarr = Ext.decode(response.responseText);
console.log(jsonarr);
var myres = jsonarr[0].Result;
console.log(myres);
switch(myres)
{
case '1':
console.log("Registration response is successfully");
Ext.Viewport.setActiveItem({xtype:'passengerdetailstwoway'});
break;
case '0':
console.log("Failed");
Ext.Msg.alert("Error","Login Failed",Ext.emptyFn);
break;
根据响应,您可以指定交换机的情况。我想建议您一种不同的方法,因为通过http将登录凭据作为GET参数发送到远程服务器不是一个好主意,相反,您应该通过HTTPS使用POST方法。现在你们可能会认为JSONP不支持POST,那个么我该怎么做呢?但若你们要在手机或iPad上安装你们的应用程序,它会在不使用JSONP的情况下从浏览器进行远程调用,这意味着你们可以使用普通的AJAX代理来做任何你们想做的事情。看看这个: 这意味着这应该是可行的:
var obj = new Object();
obj.userId = username;
obj.password = password;
var data = Ext.JSON.encode(obj);
Ext.Ajax.request({
url : 'https://login_url',
method : "POST",
headers: {
'Content-Type': 'application/json'
},
params : data,
useDefaultXhrHeader : false,
withCredentials: true,
success : function(response) {
},
failure : function(response) {
}
});
您使用的是什么后端?我想可能您的服务器响应不是jsonp,请检查回调参数。响应应该是这样的您的回调键({'data':'hello'})谢谢您的帮助,现在的问题是在chrome调试中,有未捕获的语法错误是:意外的标记:查看Java调试中的返回代码:{“jsonArray”:null,“jsonMap”:null,“jsonReturn”:“true”}最后我做错了吗?也许,但是您的响应为
null
您能告诉我您是如何处理请求的吗?:)
var obj = new Object();
obj.userId = username;
obj.password = password;
var data = Ext.JSON.encode(obj);
Ext.Ajax.request({
url : 'https://login_url',
method : "POST",
headers: {
'Content-Type': 'application/json'
},
params : data,
useDefaultXhrHeader : false,
withCredentials: true,
success : function(response) {
},
failure : function(response) {
}
});