JEditable, how to handle a JSON response?

前端 未结 4 2019
遥遥无期
遥遥无期 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:08

    There's a simple way of doing this by using the callback. .editable() converts any response to a string, so the response has to be converted to a JSON variable. The values can then be retrieved and then written using a '.text()' method. Check the code:

    $("#myField").editable("http://www.example.com/save.php", { 
        submit    : 'Save',
        cancel    : 'Cancel',
        onblur    : "ignore",
        name      : "sentText",
        callback : function(value, settings) {
            var json = $.parseJSON(value);
            $("#myField").text(json.sentText);
        }
    });
    

提交回复
热议问题