2

我需要一个跨域用户登录请求实例,请帮帮我,谢谢!!我的代码

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');     
     }
});

我的问题是,我没有收到服务器返回的值,我错了吗?

4

3 回答 3

3

你可以试试这个

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;

根据响应,您可以指定 Switch case..

于 2013-04-03T06:29:08.177 回答
0

我想向您建议一种不同的方法,因为通过 http 将登录凭据作为 GET 参数发送到远程服务器不是一个好主意,相反您应该通过 HTTPS 使用 POST 方法。现在你会认为 JSONP 不支持 POST 那么我该怎么做,但是如果你要在手机或 iPad 上安装你的应用程序,它会在不使用 JsonP 的情况下从浏览器进行远程调用,这意味着你可以使用普通的 AJAX 代理来做你想做的。看一下这个:

开发过程中如何使用json代理访问远程服务

这意味着这应该有效:

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) {

    }
});
于 2013-05-02T06:31:08.567 回答
0

嗨@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')
       }
 })

对于跨域,您需要 putwithCredentials: trueuseDefaultXhrHeader: false.

我希望能帮助你。

于 2012-08-06T16:23:58.910 回答