JEditable, how to handle a JSON response?

前端 未结 4 1953
遥遥无期
遥遥无期 2021-02-07 10:22

Right now, the server response I\'m working with sends back a JSON response like this:

{\"status\":1}

After saving, jeditable places the actual

4条回答
  •  梦谈多话
    2021-02-07 11:27

    So the solution I came up with is similar to what madcapnmckay answered here.

    var editableTextArea = $('.editable-textarea');
            editableTextArea.editable(submitEditableTextArea, {
        type      : 'textarea',
        cancel    : 'Cancel',
        submit    : 'Save',
                name            : editableTextArea.attr('id'),
                method      : 'post',
                data            : function(value, settings) {
                                            return $.fn.stripHTMLforAJAX(value);
                                        },
                event     : "dblclick",
    
        onsubmit    : function(value, settings) {
                    //jquery bug: on callback reset display from block to inline
                    $('.btn-edit').show(0, function(){$(this).css('display','inline');});
                  },
        onreset     : function(value, settings) {
                    //jquery bug: on callback reset display from block to inline
                    $('.btn-edit').show(0, function(){$(this).css('display','inline');});
                  }
      });
    

    Then the url function is

    function submitEditableTextArea(value, settings) { 
                            var edits = new Object();
                            var result = $.fn.addHTMLfromAJAX(value);
                            edits[settings.name] = [value];
                            var returned = $.ajax({
                                type            : "POST",
                                data            : edits,
                                dataType    : "json",
                                success     : function(_data) {
                                    var json = eval( _data );
                                    if ( json.status == 1 ) {
                                        console.log('success');
                                    }
                                }
                            });
                            return(result);
                        }
    

提交回复
热议问题