在sencha touch 2中发出Ajax请求问题

时间:2013-06-14 14:00:34

标签: authentication oauth sencha-touch-2

我发送ajax请求进行身份验证时遇到问题。 我没有收到错误,但Chrome中的网络说:方法:获取,状态:已取消,类型:待定 并且此请求没有回应.. 当我点击文件connection.js时,它指向这一行:

             // start the request!
              xhr.send(requestOptions.data);

&安培;我的路径名和方法得到颜色RED

这是我的代码:

   Ext.onReady(function() {
          Ext.Ajax.request({
        url: 'https://api.mysite.com/api/oauth/',
        method: 'GET',
        useDefaultXhrHeader:false,
        disableCaching: false,
        timeout:120000,

        params: {
            client_id: 'xxxxxx',
            client_secret: 'xxx',
            format: 'json'
        },
        success: function(response) {

            var resultat = Ext.JSON.decode(response.responseText);
     //the response is :           {"status":"ok","auth_token":"xxxxxxxxxxx"}
            if (resultat.status === "ok") {
                if (!resultat.access_token === "") {

                    access_token = resultat.access_token;
                    me.sessionToken = resultat.sessionToken;
                }
                else
                {
                    new Ext.Ajax.request({
                        url: 'https://api.mysite.com/api/oauth/signin',
                        method: 'post',
                        params: {
                            username: username,
                            password: password,
                            authtoken: resultat.access_token,
                            format: 'json'
                        },
                        success: function(response) {

                            var loginResponse = Ext.JSON.decode(response.responseText);

                            if (loginResponse.success === "true") {
                                // The server will send a token that can be used throughout the app to confirm that the user is authenticated.
                                me.sessionToken = loginResponse.sessionToken;
                                me.signInSuccess();     //Just simulating success.
                            } else {
                                me.signInFailure(loginResponse.message);
                            }
                        },
                        failure: function(response) {
                            me.sessionToken = null;
                            me.signInFailure('Login failed. Please try again later.');
                        }

                    });

                }
                // The server will send a token that can be used throughout the app to confirm that the user is authenticated.


            } else {
                //exception
            }
        }
           ,
           failure: function(response) {
                 me.sessionToken = null;
                  Ext.Msg.alert('failed !!');    // its what it shows me 
                }
         });

0 个答案:

没有答案