我如何对 jQuery 序列化的表单进行 PHP 反序列化? [英] How do I PHP-unserialize a jQuery-serialized form?

查看:35
本文介绍了我如何对 jQuery 序列化的表单进行 PHP 反序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用$('#form').serialize(),我能够将其发送到PHP 页面.现在我如何在 PHP 中反序列化它?它是在 jQuery 中序列化的.

Using $('#form').serialize(), I was able to send this over to a PHP page. Now how do I unserialize it in PHP? It was serialized in jQuery.

推荐答案

您不必通过 jquery serialize 方法对 PHP 中的任何内容进行反序列化.如果您序列化数据,如果您使用 GET 方法 ajax 请求,则应将其作为查询参数发送到 PHP,如果您使用 POST ajax 请求,则应将其作为查询参数发送到 PHP.因此,在 PHP 中,您将根据请求类型访问诸如 $_POST["varname"]$_GET["varname"] 之类的值.

You shouldn't have to unserialize anything in PHP from the jquery serialize method. If you serialize the data, it should be sent to PHP as query parameters if you are using a GET method ajax request or post vars if you are using a POST ajax request. So in PHP, you would access values like $_POST["varname"] or $_GET["varname"] depending on the request type.

serialize 方法只是获取表单元素并将它们放在字符串形式中."varname=val&var2=val2"

The serialize method just takes the form elements and puts them in string form. "varname=val&var2=val2"

这篇关于我如何对 jQuery 序列化的表单进行 PHP 反序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆