反向序列化()-jquery
我使用此代码发送了 ajax 请求的数据(json);
var formdata = $("#customForm").serialize();
type: "post",
dataType: "json",
data: formdata,
在php文件中,有可能反向序列化吗?
或者我需要为所有字段创建类似的内容: $pass = $_POST['pass'];
?
谢谢
I sent my data (json) for an ajax request with this code;
var formdata = $("#customForm").serialize();
type: "post",
dataType: "json",
data: formdata,
In the php file, there is possible reverse the serialize?
or i need to make something like that: $pass = $_POST['pass'];
for all fields?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你的“或”陈述正朝着正确的方向前进。数据应该在 $_POST 数组中可用,而不需要“反序列化”任何内容。
编辑
尝试命名您的输入字段,以便它们全部作为数组进入 post 变量:
然后在 post 数组中您可以访问所有表单数据,例如:
it sounds like you are headed in the right direction with your "or" statement. The data should be available in the $_POST array without needing to "deserialize" anything.
EDIT
Try to name your input fields so that they all come into the post variable as an array:
Then in the post array you can access all the form data like:
尝试 PHP 的
extract
函数:示例< /strong>:
输出:
欺负
被人
会导致任何
key =>;
对被提取到变量中。$_POST
数组中存在的值就像对
$_POST
数组中的所有变量执行$pass = $_POST['pass']
一样。说明:
extract
会将变量从数组导入到当前符号表中。它检查每个键以查看它是否具有有效的变量名称。它还检查与符号表中现有变量的冲突。
来自 PHP 文档(摘录)
Try PHP's
extract
function:Example:
Outputs:
Applied to Your Situation:
extract($_POST);
Would result in whatever
key => value
pairs present in the$_POST
array being extracted into variables.Like doing
$pass = $_POST['pass']
on all variables in the$_POST
array.Explanation:
extract
will import variables from an array into the current symbol table.It checks each key to see whether it has a valid variable name. It also checks for collisions with existing variables in the symbol table.
From PHP Docs (extract)
是的。您只需要像
$pass = $_POST['pass']
那样访问:)。Yeah. You just need to acces like
$pass = $_POST['pass']
:).