1. #1
    Ext User
    Join Date
    Nov 2007
    Posts
    12
    Vote Rating
    0
    tngoldmant is on a distinguished road

      0  

    Default Returning success from a AJAX call

    Returning success from a AJAX call


    Hi All,
    I have a RoR method that returns the following for success:
    ....
    Code:
     render :nothing => true, :status => "200"
    ....

    But the js fuction is not picking up the reponse:
    Code:
    add_new_topic_form.addButton({
            text: 'Submit',
            handler: 
            function(){
                add_new_topic_form.form.submit({
                    url:'/mainclient/create', 
                    method:'POST',
                    success:function(){Ext.Msg.alert('SUCCCESS');},
                    failure:function(){Ext.Msg.alert('FAILURE');}           
                })
           }
        });
    The failure code get called correctly when I return a 409 response code:
    Code:
    render :nothing => true, :status => "409"
    But the "200" response code is not being picked up.

    What am I missing?

    TIA for all help rendered

  2. #2
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,962
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default


    HTTP Status codes are not strings- should be numeric. Lose the quotes when you set the PHP Http status.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    2
    tryanDLS is on a distinguished road

      0  

    Default


    Please don't cross-post the same question to multiple forums - I have deleted your other post.

  4. #4
    Ext User
    Join Date
    Nov 2007
    Posts
    12
    Vote Rating
    0
    tngoldmant is on a distinguished road

      0  

    Default


    I still get the same behavior if I return a numeric rather then a string:

    Code:
    def create
         topic = Topic.find_by_title(params[:title])
         if topic
           # user tried to create a existing topic
           render :nothing => true, :status => 409
         else
            render :nothing => true, :status => 200
         end
         
      end
    The success response method in the .js file is still not getting called.

  5. #5
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,962
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default


    You are sending an HTTP status in the JSON response? why?

    and 'nothing' should be 'success'

    Your JSON response should look like:
    Code:
    {success:true }
    What Ext Ajax operation are you invoking? Tough to help if we don't know what you're doing....

    could you post your actual JSON response return by your server (not RoR script)?
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  6. #6
    Ext User
    Join Date
    Nov 2007
    Posts
    12
    Vote Rating
    0
    tngoldmant is on a distinguished road

      0  

    Default


    Ok, I am creating a form, here is the js code:
    Code:
    var add_new_topic_form = new Ext.FormPanel
    ({
            labelAlign: 'top',
            title: 'Add New Topic',
    
            bodyStyle:'padding:5px',
            items: [{
                layout:'column',
                border:false,
                items:[{
                    columnWidth:1,
                    layout: 'form',
                    border:false,
                    items: [{
                        xtype:'textfield',
                        fieldLabel: 'Title',
                        name: 'title',
                        value: 'Enter topic title here',
                        anchor:'95%'
                    }, {
                        xtype:'textfield',
                        fieldLabel: 'Category',
                        name: 'category',
                        value: 'Select topic category here',
                        anchor:'95%'
                    },{
                        xtype:'textfield',
                        fieldLabel: 'Search Depth',
                        name: 'search_depth',
                        value: '5',
                        anchor:'25%'
                    }]
                }]
            },{
                xtype:'tabpanel',
                plain:true,
                activeTab: 0,
                height:235,
                defaults:{bodyStyle:'padding:10px'},
                items:[{
                    title:'Description',
                    layout:'form',
                    defaults: {width: 230},
                    defaultType: 'htmleditor',
                    items: [{
                        fieldLabel: 'Description',
                        name: 'description',
                        height: 175,
                        width: 450,
                        allowBlank:false,
                        value: 'Enter topic description here'
                    }]
                    },{
                    title:'Notification',
                    layout:'form',
                    width: 230,
                    defaultType: 'textfield',
                    items: [{
                        fieldLabel: 'Email',
                        width: 450,
                        name: 'email_notification',
                        value: 'Enter email addesses, comma seperated'
                    },{
                        fieldLabel: 'SMS',
                        width: 450,
                        name: 'sms_notification',
                        value: 'Enter SMS number, comma seperated'
                    },{
                        fieldLabel: 'RSS',
                        width: 450,
                        name: 'rss_notification',
                        value: 'Enter Yes'
                    }]
                }]
            }]
        });
    With 2 buttons, a Submit and a Cancel button:

    Code:
     add_new_topic_form.addButton({
            text: 'Submit',
            handler: 
            function(){
                add_new_topic_form.form.submit({
                    url:'/mainclient/create', 
                    method:'POST',
                    success:function(){
                        Ext.Msg.alert('SUCCCESS');
                    },
                    failure:function(){
                        Ext.Msg.alert('FAILURE');    
                    }           
                })
           }
        });
    The user fills out the form and clicks Submit, which call a Rails def called create in a contoller called mainclient:
    Code:
    def create
         topic = Topic.find_by_title(params[:title])
         if topic
           # user tried to create a existing topic
           render :nothing => true, :status => 409
         else
            render :nothing => true, :status => 201
         end
         
      end
    My intention is to create a RESTful set of web services. I dont believe that I am invoking JSON in the web service, thought that might be how the data is posted to the back end. In this case, if the the user is creating a new topic, then the Rails method should return reponse code 200. If the Topic exist, then the Rails method should return 409

    TIA for all assistance provided

  7. #7
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,962
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default Ah, yes, REST was the keyword I was missing.

    Ah, yes, REST was the keyword I was missing.


    You'll need to examine the HTTP Statuses closely after each submit (possibly at a lower level in the AJAX stack to get the 'resolution' you'll need for REST.

    Ext's (default) Ajax success/failure callbacks and events are predicated on this decision tree:
    • HTTPStatus => 200 && <=300 are considered a transport success
    • Anothing else is an AJAX transport failure (and is treated as such).
    So, you're likely thinking you want to use the 400-499 status range for REST state management and spending a fair amount of time coding for this within the various failure events/callbacks. Out-of-the-box, Ext's AJAX widget/form linkage is not designed for REST.

    The default behavior for Ext form actions is based on a JSON response returned by your servers post attempt (with an HTTP status 200-299, anything else is a comm failure):
    Code:
    {
        success: false,
        errors: {
            topic: "Already Exists",
            category: "Category not defined."
        }
    }
    So, it would seem you have a decision to make:

    1) Use the existing Form Post Response mechanism (not all that bad actually )
    2) or, write your own REST-based transport classes for Ext.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  8. #8
    Ext User
    Join Date
    Nov 2007
    Posts
    12
    Vote Rating
    0
    tngoldmant is on a distinguished road

      0  

    Default


    Thanks Doug for your advise and assistance. I opted to just use 450-499 response codes for the return status for my custom return codes.

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar