問題描述
使用$('#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 反序列化?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!