代码之家  ›  专栏  ›  技术社区  ›  Roman Suvorov

可编辑的官方示例(jsFiddle)不起作用

  •  2
  • Roman Suvorov  · 技术社区  · 10 年前

    我正在学习X-editable库,我想知道为什么官方网站上的一个示例不起作用。

    JavaScript

    $('#username').editable({
        type: 'text',
        url: '/post',    
        pk: 1,    
        title: 'Enter username',
        ajaxOptions: {
            dataType: 'json'
        },
        success: function(response, newValue) {
            if(!response) {
                return "Unknown error!";
            }          
    
            if(response.success === false) {
                 return response.msg;
            }
        }        
    });
    
    //ajax emulation
    $.mockjax({
        url: '/post',
        responseTime: 200,
        response: function(settings) {
            if(settings.data.value) {
                this.responseText = '{"success": true}';
            } else {
                this.responseText = '{"success": false, "msg": "required"}';
            }
        }
    }); 
    

    请在此处查看完整代码: http://jsfiddle.net/xBB5x/62/

    当我单击一个可编辑文本,更改它并单击“确定”按钮时,它之后什么都不会发生。我只能看到一个加载图标。有人能解释一下它怎么了吗?非常感谢。

    (摘自 http://vitalets.github.io/x-editable/demo-bs3.html 部分“更多示例和技巧(jsFiddle)”)

    1 回复  |  直到 10 年前
        1
  •  2
  •   Roman Suvorov    10 年前

    您应该更新jsFiddle外部资源-jquery.mockjax.js
    这一点很好:
    https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js

    推荐文章