我尝试使用Ajax提交数据
X-Editable
运行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'
});
});
});
问题是这会创建它应该创建的可编辑字段,但它不会调用
后.php
脚本(与第一个示例不同)。我做错了什么?