如何用PHP对序列化的jQuery序列化PHP? [英] How do I PHP-unserialize a jQuery-serialized form?

查看:95
本文介绍了如何用PHP对序列化的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请求,则应将其作为vars发送.因此,在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"

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

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