1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    8
    Vote Rating
    0
    sagarsgiri is on a distinguished road

      0  

    Default Answered: How to set the proxy URL

    Answered: How to set the proxy URL


    Hi,

    How to set a proxy URL in ExtJS?

    In Sproutcore, we have a Buildfile where we set -

    Code:
    proxy '/login' :to  => 'localhost:4567'
    In ExtJS, to post a JSON object, we use the following code:

    Code:
         Ext.Ajax.request({
                                 url:'/login',
                                 method: 'POST',
                                 headers: {'Content-Type':'application/json'},
                                 jsonData:{"userName": value,
                                      "password": value,
                                 },
                                 success:function(response){ 
                                         obj = Ext.util.JSON.decode(response.responseText);
                                         Ext.Msg.alert('Status', '', obj);
                                 },
                                 failure:function(response){ 
                                     if(action.failureType == 'server'){ 
                                         obj = Ext.util.JSON.decode(response.responseText); 
                                         Ext.Msg.alert('', obj.errors.reason); 
                                     }else{ 
                                         Ext.Msg.alert('','' +response.responseText); 
                                     } 
                                     
                                 }    
                             });
    Where should I set the URL -> http://localhost:4567 ??

    The server is running @ localhost:4567. (I have to send JSON object to the url "http://localhost:4567/login" to get a response back.)


    Thanks in advance.

  2. @sagarsgiri: we've already discussed this on your other thread:

    http://www.sencha.com/forum/showthread.php?144031

    To reiterate what I explained there, you cannot use an alternative server for an Ajax request due to the same origin policy.

    You'll need to handle the login request on the same webserver that serves up your page. This could simply forward the request on to your other server if that's what you want.

  3. #2
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,167
    Vote Rating
    28
    Answers
    83
    jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough jay@moduscreate.com is a jewel in the rough

      0  

    Default


    /login should be Fine.

    You should be placing 'var ' in front of your obj reference declarations.

    Jay Garcia @ModusJesus || Modus Create co-founder
    Ext JS in Action author
    Sencha Touch in Action author

    Get in touch for Ext JS & Sencha Touch Touch Training

    We are also working on Video-based Sencha Touch training: Check it out here.

  4. #3
    Sencha User skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,078
    Vote Rating
    112
    Answers
    453
    skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold

      0  

    Default


    @sagarsgiri: we've already discussed this on your other thread:

    http://www.sencha.com/forum/showthread.php?144031

    To reiterate what I explained there, you cannot use an alternative server for an Ajax request due to the same origin policy.

    You'll need to handle the login request on the same webserver that serves up your page. This could simply forward the request on to your other server if that's what you want.