1. #1
    Sencha User
    Join Date
    May 2013
    Posts
    19
    Vote Rating
    0
    Hasret is on a distinguished road

      0  

    Default Unanswered: Ajax request issue in sencha touch 2

    Unanswered: Ajax request issue in sencha touch 2


    I have a problem with sending an ajax request for the authentification.. i dont get errors but Network in chrome says : method : get , status : canceled , type : pending and no response from this request .. when i click on the file connection.js it point in this line :

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


    & my path name and the method get have the color RED
    here is my code :


    Code:
    Ext.onReady(function() {
            Ext.Ajax.request({  
                url: 'https://api.mysite.com/api/oauth/',
                method: 'GET',
                useDefaultXhrHeader:false,
                disableCaching: false,
                timeout:120000,
                params: {
                    client_id: 'MurRpoucHsoon33',
                    client_secret: 'lO%3DodhaK64dayS',
                    format: 'json'
                },
                success: function(response) {
    
    
                    var resultat = Ext.JSON.decode(response.responseText);
                     Ext.Msg.alert(resultat);
                    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 !!');
    //                me.signInFailure('Login failed. Please try again later.');
                }
            });
    
    
    });
    
    


  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    What is the actual error? Is it the CORS error?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2013
    Posts
    19
    Vote Rating
    0
    Hasret is on a distinguished road

      0  

    Default


    there is no error in the console , Network in chrome says : method : Get , status : canceled , type : pending
    i tested with safari & ios similator , the request failled , it shows me the alert that i made in the fonction FAILLURE

    I put in the httpd-vhosts.conf inside of directory section of apache server

    Header set Access-Control-Allow-Origin "*"

    But no effect...
    Sans titre.jpg


    Ps: Im using HTTPS it can be the problem .


  4. #4
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    118
    Answers
    8
    Vote Rating
    2
    vnggui is on a distinguished road

      0  

    Question Ajax fail quietly

    Ajax fail quietly


    I have same issue in Chrome. When sending several requests a few of them are marked as red with canceled status.

    My guess is browser time out, but I cannot increase the browser time out via Sencha code like:

    Ext.Ajax.request({
    ..
    timeout: xxxx
    ...
    })

    or
    Ext.Ajax.setTimeout(xxxx);

    As per desktop Chrome maximum timeout is around 60 seconds, desktop Safari around 90 seconds.

    Any idea about this?