I am using X-Editable plugin in my php application to update fields of my table and use POST file to update the database.
我在我的php应用程序中使用X-Editable插件来更新我的表的字段并使用POST文件来更新数据库。
Here is form code:
这是表单代码:
<table id="restaurant" class="table table-bordered table-striped">
<tbody>
<?php
echo '
<tr>
<td style="width:15%">Restaurant name</td>
<td style="width:50%"><a href="#" id="name" data-type="text" data-pk="'. escape($arrValues[$i]->r_id) .'" data-name="name" data-placeholder="Required" data-original-title="Enter Restaurant Name" class="editable editable-click" style="display: inline;">'. escape($arrValues[$i]->name) .'</a></td>
<td style="width:35%"><span class="text-muted">Enter restaurant name.</span></td>
</tr>';
?>
</tbody>
</table>
Here is the X-editable JS I am using at the bottom of the page:
这是我在页面底部使用的X-editable JS:
<script>
jQuery(document).ready(function() {
//initializes all global values and plugin essentials
FormEditable.init();
//below function is only initialized on one field for debug purposes
$(function(){
$('#name').editable({
url: 'post.php'
});
});
});
</script>
Here is the contents of my Post.php file:
这是我的Post.php文件的内容:
<?php
require 'core/init.php';
$pk = $_POST['pk']; //primary key aka ID
$name = $_POST['name']; //name of the field
$value = $_POST['value']; //value of the field
if (!empty($value)){
$result = mysql_query('update Restaurants set '.mysql_escape_string($name).'="'.mysql_escape_string($value).'" where r_id = "'.mysql_escape_string($pk).'"');
print_r($_POST);
} else {
header('HTTP 400 Bad Request', true, 400);
echo "This field is required!";
}
?>
When I update the field in the application the value gets changed in the DOM but the value is not updated in the database. This my first time using X-Editable plugin and I not very strong in JS AJAX calls. Could someone please let me know how I can debug this and figure out why my value is not being pushed to the database.
当我更新应用程序中的字段时,DOM中的值会更改,但数据库中的值不会更新。这是我第一次使用X-Editable插件,而且在JS AJAX调用中我不是很强。有人可以告诉我如何调试这个并找出为什么我的价值没有被推送到数据库。
Any help will be greatly appreciated.
任何帮助将不胜感激。
3 个解决方案
#1
3
To properly debug this you might use your Browsers Console! Especially the "network" tab is a great help in debugging this.
要正确调试,您可以使用浏览器控制台!特别是“网络”选项卡在调试时非常有帮助。
You included the scripts successfully, used the correct markup, so that the DOM gets changed. Now the next step in debugging is, to ensure that the ajax request (pushing the data) to your post.php is made.
您成功包含了脚本,使用了正确的标记,以便更改DOM。现在,调试的下一步是确保将ajax请求(推送数据)发送到post.php。
To send something you need to set ajaxOptions put, like this:
要发送一些东西你需要设置ajaxOptions put,如下所示:
$('#name').editable({
type: 'text',
url: 'post.php',
ajaxOptions: {
type: 'put'
}
});
You debug the Ajax request by checking the "network" tab of your console. Open the network console before you edit the field. Then edit it and watch the new request appearing in the console. By clickling the log entry in the console, you see the data send from the browser to your script.
您可以通过检查控制台的“网络”选项卡来调试Ajax请求。在编辑字段之前打开网络控制台。然后编辑它并观察出现在控制台中的新请求。通过单击控制台中的日志条目,您可以看到从浏览器发送到脚本的数据。
In your post.php you might add a var_dump($_POST); to see all the parameters incoming.
在post.php中你可以添加一个var_dump($ _ POST);看到所有传入的参数。
#2
1
Just change from
只是改变
ajaxOptions: {
type: 'put'
}
into
成
ajaxOptions: {
type: 'POST'
}
and get your PHP ready for update mysql as usual.
并像往常一样让你的PHP准备好更新mysql。
#3
0
The issue was caused by the mockjax plugin which was overwriting the ajax function with a different url. The issue was resolved when I removed all of the mockjax references from the page.
这个问题是由mockjax插件引起的,该插件用不同的url覆盖了ajax函数。当我从页面中删除所有mockjax引用时,问题得以解决。
Thank you Jens-Andre Koch for your help!
谢谢Jens-Andre Koch的帮助!
#1
3
To properly debug this you might use your Browsers Console! Especially the "network" tab is a great help in debugging this.
要正确调试,您可以使用浏览器控制台!特别是“网络”选项卡在调试时非常有帮助。
You included the scripts successfully, used the correct markup, so that the DOM gets changed. Now the next step in debugging is, to ensure that the ajax request (pushing the data) to your post.php is made.
您成功包含了脚本,使用了正确的标记,以便更改DOM。现在,调试的下一步是确保将ajax请求(推送数据)发送到post.php。
To send something you need to set ajaxOptions put, like this:
要发送一些东西你需要设置ajaxOptions put,如下所示:
$('#name').editable({
type: 'text',
url: 'post.php',
ajaxOptions: {
type: 'put'
}
});
You debug the Ajax request by checking the "network" tab of your console. Open the network console before you edit the field. Then edit it and watch the new request appearing in the console. By clickling the log entry in the console, you see the data send from the browser to your script.
您可以通过检查控制台的“网络”选项卡来调试Ajax请求。在编辑字段之前打开网络控制台。然后编辑它并观察出现在控制台中的新请求。通过单击控制台中的日志条目,您可以看到从浏览器发送到脚本的数据。
In your post.php you might add a var_dump($_POST); to see all the parameters incoming.
在post.php中你可以添加一个var_dump($ _ POST);看到所有传入的参数。
#2
1
Just change from
只是改变
ajaxOptions: {
type: 'put'
}
into
成
ajaxOptions: {
type: 'POST'
}
and get your PHP ready for update mysql as usual.
并像往常一样让你的PHP准备好更新mysql。
#3
0
The issue was caused by the mockjax plugin which was overwriting the ajax function with a different url. The issue was resolved when I removed all of the mockjax references from the page.
这个问题是由mockjax插件引起的,该插件用不同的url覆盖了ajax函数。当我从页面中删除所有mockjax引用时,问题得以解决。
Thank you Jens-Andre Koch for your help!
谢谢Jens-Andre Koch的帮助!