Submitting data via Ajax in X-Editable

江枫思渺然 提交于 2020-01-06 04:27:26

问题


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'
});

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}

And related 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'                   
        });  
    });
});

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?


回答1:


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);
                          // }, 
      });  


来源:https://stackoverflow.com/questions/37876375/submitting-data-via-ajax-in-x-editable

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