首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >sencha touch2登录示例

sencha touch2登录示例
EN

Stack Overflow用户
提问于 2012-08-06 16:25:07
回答 3查看 1.8K关注 0票数 2

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

代码语言:javascript
复制
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');     
     }
});

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

EN

回答 3

Stack Overflow用户

发布于 2013-04-03 14:29:08

你可以试试这个

代码语言:javascript
复制
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;

根据响应,您可以指定切换情况。

票数 3
EN

Stack Overflow用户

发布于 2012-08-07 00:23:59

Hi @jesse你可以尝试这样的跨域的东西,

代码语言:javascript
复制
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: trueuseDefaultXhrHeader: false

希望能对你有所帮助。

票数 0
EN

Stack Overflow用户

发布于 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

这意味着这应该是可行的:

代码语言:javascript
复制
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) {

    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11824789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档