问题
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