I just created an x-editable form :
我刚刚创建了一个x-editable表单:
<a href='#' class='username'
data-pk='<?php echo $key['idca']; ?>'
data-type="text"
data-placement="right"> <?php echo $key['categoryname']; ?> </a>
Then I created Javascript function to handle x-editable form :
然后我创建了Javascript函数来处理x-editable表单:
$.fn.editable.defaults.success = function() { $(this).show() };
$.fn.editable.defaults.mode = 'inline';
$('.username').editable({
url:'edit.php',
pk:'1',
type:'text',
send:'always',
ajaxOptions:{
dataType:'json'
},
success: function(response, newValue) {
window.alert('oke');
},
error: function(response, newValue) {
window.alert('failed');
}
});
and in PHP I just create as follow :
在PHP中,我创建如下:
<?php
$pk = $_POST['pk'];
$val = $_POST['value'];
$name = $_POST['name'];
print_r($_POST);
?>
But why I received message "undefined index pk, value, name" on window alert, which means I failed posting pk, value, name from x-editable..
但是为什么我在窗口警告中收到“undefined index pk, value, name”的消息,这意味着我没有发布pk, value, name from x-editable。
Need helps, thank you very much
需要帮助,非常感谢
2 个解决方案
#1
0
Given the following HTML
鉴于以下HTML
<a href="#" class="username"
data-pk="<?php echo $key['idca']; ?>"
data-type="text"
data-placement="right"
>
<?php echo $key['categoryname']; ?>
</a>
You can use this jQuery:
您可以使用以下jQuery:
$.fn.editable.defaults.success = function() { $(this).show() };
$('#username').editable({
type: 'text', // optionnal if you've set up the data-type attribute
pk: $(this).data('pk'), // optionnal if you've set up the data-pk attribute
url: 'edit.php', // mandatory
title: 'Enter username'
});
This should work as per the documentation. There is no need for you to do the $.ajax({});
by yourself.
这应该按照文档工作。您不需要做$.ajax({});由你自己。
#2
0
A little late but on php side when you response you should use json_encode because x-editable is expecting you to return with json string.
稍微晚一点,但在php方面,当你响应时,应该使用json_encode,因为x-editable希望你返回json字符串。
$pk = $_POST['pk'];
$val = $_POST['value'];
$name = $_POST['name'];
echo json_encode($_POST);
die();
#1
0
Given the following HTML
鉴于以下HTML
<a href="#" class="username"
data-pk="<?php echo $key['idca']; ?>"
data-type="text"
data-placement="right"
>
<?php echo $key['categoryname']; ?>
</a>
You can use this jQuery:
您可以使用以下jQuery:
$.fn.editable.defaults.success = function() { $(this).show() };
$('#username').editable({
type: 'text', // optionnal if you've set up the data-type attribute
pk: $(this).data('pk'), // optionnal if you've set up the data-pk attribute
url: 'edit.php', // mandatory
title: 'Enter username'
});
This should work as per the documentation. There is no need for you to do the $.ajax({});
by yourself.
这应该按照文档工作。您不需要做$.ajax({});由你自己。
#2
0
A little late but on php side when you response you should use json_encode because x-editable is expecting you to return with json string.
稍微晚一点,但在php方面,当你响应时,应该使用json_encode,因为x-editable希望你返回json字符串。
$pk = $_POST['pk'];
$val = $_POST['value'];
$name = $_POST['name'];
echo json_encode($_POST);
die();