我需要一个跨域的用户登录请求实例,请帮帮我,谢谢!我的代码
Ext.data.JsonP.request({
url: 'http://25.30.2.3:8080/newvbo/applyaction!longin',
params: {
username:'13881901678',
password:'111111',
},
success: function(response, opts) {
alert('1');
},
failure: function(response, opts) {
alert('2');
}
});我的问题是,我没有收到服务器返回的值,我错了吗?
发布于 2013-04-03 14:29:08
你可以试试这个
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;根据响应,您可以指定切换情况。
发布于 2012-08-07 00:23:59
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')
}
})对于跨域,您需要放入withCredentials: true和useDefaultXhrHeader: false。
希望能对你有所帮助。
发布于 2013-05-02 14:31:09
我想向您推荐一种不同的方法,因为通过http将登录凭据作为GET参数发送到远程服务器并不是一个好主意,相反,您应该通过HTTPS使用POST方法。现在你可能会认为JsonP不支持POST,那么我该怎么做呢,但是如果你打算在手机或iPad上安装你的应用程序,它将在不使用JSONP的情况下从浏览器进行远程调用,这意味着你可以使用普通的AJAX代理来做任何你想做的事情。看看这个:
How to use json proxy to access remote services during development
这意味着这应该是可行的:
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) {
}
});https://stackoverflow.com/questions/11824789
复制相似问题