在X-Editable中通过Ajax提交数据 [英] Submitting data via Ajax in X-Editable

查看:585
本文介绍了在X-Editable中通过Ajax提交数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 X-Editable 通过Ajax提交数据,并且运行url参数中定义的php脚本时遇到麻烦.实际上,我从工作中得到了基本的例子:

I am trying to submit data via Ajax using X-Editable and having trouble with running the php script defined in url parameter. Actually, I got basic example from working:

HTML

<a href="#" id="username" data-type="text" data-pk="1" data-name="username" data-original-title="Enter username" class="editable">superuser123</a>

JS:

$('#username').editable({
    url: 'post.php',
    type: 'text',
    pk: 1,
    name: 'username',
    title: 'Enter username'
});

这正在起作用(执行了post.php).但是现在我想拥有更多可编辑的字段,并在单击按钮时运行它们.这是我的html(我正在使用Smarty):

And this is working (post.php is executed). But now I want to have more editable fields and to run them on button click. This is my html (I am using Smarty):

{foreach from=$categories key="category_key" item="category_item"}
<tr>
    <th scope="row">{$category_key + 1}</th>
    <td>
        <span  id="edit-button-{$category_key + 1}" data-pk="1" data-original-title="Edit category name"  data-toggle="#edit">
            {$category_item["name"]}
        </span>
        <button  class="btn edit"><span class="glyphicon glyphicon-pencil"></span></button>
    <td>0</td>
</tr>
{/foreach}

以及相关的Javascript:

$(document).ready(function() {
    //toggle `popup` / `inline` mode
    $.fn.editable.defaults.mode = 'inline';     

    $('.edit').click(function(e){    
        e.stopPropagation();
        var button = $(this).prev('span').attr('id');

        $('#'+button).editable('toggle',{
            url: 'post.php',
            type: 'text',
            pk: 1,
            name: button,
            title: 'Edit category'                   
        });  
    });
});

问题在于这将创建应有的可编辑字段,但它不会调用post.php脚本(与第一个示例不同).我在做什么错了?

The thing is that this creates editable fields as it should, but it doesn't call post.php script (unlike in the first example). What I am doing wrong?

推荐答案

我已经通过下一步解决了它:

I have solved it by doing next:

$('#'+button).editable({
                           url: 'post.php',
                           type: 'text',
                           name: button,
                           title: 'Edit category',
                           ajaxOptions:{
                            type:'post'
                           } ,
                          //  success: function(data) {
                          //   alert(data);
                          // }, 
      });  

这篇关于在X-Editable中通过Ajax提交数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆