Jeditable CANCEL callback from AJAX callback?

不羁的心 提交于 2019-11-27 18:24:59

问题


I see some answers for the Jeditable plugin to use a callback function from AJAX using complete callback function.

I know that the Jeditable has a callback function for the SUBMIT button, so I would like to know if there is a way to have a callback for the CANCEL button? I haven't found on the plugin docs.

Thanks for reply,

Carlos

PD. This is the source I see for COMPLETE from AJAX callback:

$("#editable_text").editable(submitEdit, { 
            indicator : "Saving...",
            tooltip   : "Click to edit...",
            name : "Editable.FieldName",
            id   : "elementid",
            type : "text",
});
function submitEdit(value, settings)
{ 
   var edits = new Object();
   var origvalue = this.revert;
   var textbox = this;
   var result = value;
   edits[settings.name] = [value];
   var returned = $.ajax({
           url: "http://URLTOPOSTTO", 
           type: "POST",
           data : edits,
           dataType : "json",
           complete : function (xhr, textStatus) 
           {
               var response =  $.secureEvalJSON(xhr.responseText);
               if (response.Message != "") 
               {
                   alert(Message);
               } 
           }
           });
   return(result);
 }

回答1:


Yes, there is a "onreset" parameter that is called when clicking cancel, or more generally, before jEditable resets the control back to the state before it was clicked. Add this to your code:

$("#editable_text").editable(submitEdit, { 
    //...
    onreset: jeditableReset,
    //...
});

function jeditableReset(settings, original) {
   // whatever you need to do here
}

This is documented in the header of the jquery.jeditable.js file.

Another note - if you don't submit on blur (you don't appear to be in the sample), the onreset event will fire then too.



来源:https://stackoverflow.com/questions/1128760/jeditable-cancel-callback-from-ajax-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!