我正在尝试使用 X-Editable 通过 Ajax 提交数据并且在运行 url 参数中定义的 php 脚本时遇到问题。实际上,我从工作中得到了基本的例子:
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):
{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
脚本(与第一个示例不同)。我做错了什么?
最佳答案
我通过执行以下操作解决了这个问题:
$('#' + button).editable({
url: 'post.php',
type: 'text',
name: button,
title: 'Edit category',
ajaxOptions: {
type: 'post'
},
// success: function(data) {
// alert(data);
// },
});
关于php - 在 X-Editable 中通过 Ajax 提交数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37876375/