AnanthaKN / jquery-in-place-editor

Automatically exported from code.google.com/p/jquery-in-place-editor
Other
0 stars 0 forks source link

Server Post Response #91

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. submit a post to my aspx page
2. post page works correctly
3. on success i want to show a div with text returned from the server

What is the expected output? What do you see instead?
How do I determine what is returned back from the server after it does my post. 
like with callback: function(original_element, html, original){ how do i get 
these values after i do a post to the server??

What version of the product are you using? On what operating system?
2.3.0 - Windows 7 - Firefox 3.6.3

Please provide any additional information below.

Code using to do the post

$(".editText").editInPlace({
    show_buttons: true,
    field_type: "text",
    saving_image: "busy.gif",
    url: 'jQuerryPostBacks.aspx',
    params: "action=updatePageName",
    success: function(response){
    //do something if successful    
    },
});

Original issue reported on code.google.com by Adrian.L...@gmail.com on 19 Apr 2011 at 12:22

GoogleCodeExporter commented 8 years ago
I have the same issue. For most of my AJAX stuff I return an object with 
parameters. The values of the parameters determine what happens. How can I 
access the returned object? Normally it would be whatever is returned by the 
jQuery AJAX functions. You could do the same with your success function.

1. Submit a post to the server
2. Response returned by server should be passed to the success() callback if 
the callback is defined. If not, then simply apply the response as you do now.

Thanks
Steve

Original comment by rhythmicdevil@gmail.com on 22 Feb 2012 at 3:14

GoogleCodeExporter commented 8 years ago
I made some changes to the code to get the effect that I wanted. I changed the 
content of the success function to the following:

success: function(html){
    var new_text = html || that.settings.default_text;

    /* put the newly updated info into the original element */
    // FIXME: should be affected by the preferences switch
    //that.dom.html(new_text);
    // REFACT: remove dom parameter, already in this, not documented, should be easy to remove
    // REFACT: callback should be able to override what gets put into the DOM
    //console.log('HTML', html);

    that.triggerCallback(that.settings.success, that, html);
},

And this is how I implement it:

    $('.editable').each(function(){
        var editURL = $(this).closest('table').attr('editURL');
        $(this).editInPlace({
            'url' : editURL,
            'callback_skip_dom_reset' : true,
            'value_required' : true,
            'success' : function(element, response){
                if(response.status == 'success'){
                    $(this).html(response.msg.update_value);
                }else{
                    $(this).html(element.originalValue);
                    $.popDialog(response);

                }
            }
        });
    });

This assumes that any table that has a custom attribute of editURL that has 
children with a class of editable will have this applied. The change to the 
success function allows me to access my response object which looks like 
something like:

{
    "title":"data",
    "msg":{
        "update_value":"cheeseburger.net",
        "element_id":"undefined",
        "original_html":"cheeseburger.coms",
        "original_value":"cheeseburger.coms"
    },
    "status":"success"
}

The only other thing that I would like is to have a new function added to the 
editor so that I can use a function to define the URL.

Steve

Original comment by rhythmicdevil@gmail.com on 22 Feb 2012 at 4:08