我有一个 HTML 表单,单击提交时,在
$('#result').text(JSON.stringify($('form').serializeObject()));
我的 HTML 表单有action="filename.php"
* 和它的方法作为post
现在我想在 PHP 文件中发送/读取这些值,并且应该能够对它们执行操作。就像,在屏幕上打印它们(Echo)或将它们插入数据库。
请帮助如何在我的 php 文件中获取可读/可访问格式的值?提前致谢。
In filename.php
$formData = json_decode($_POST['fieldname']);
will decode the json string from your form post into a PHP object. If you want an array pass true
as the second param to the json_decode method
You'll need to replace fieldname
with the attribute name from your HTML / Javascript that holds the json data.
您可以正常发布变量(没有 JQuery 序列化到 JSON),然后您可以$_POST
通过filename.php
.