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
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:
<input name="myformdata[first_name]" id="first_name" />
<input name="myformdata[last_name]" id="last_name" />
Then in the post array you can access all the form data like:
<?php $form_data_array = $_POST['myformdata']; ?>
Try PHP's extract
function:
extract($_POST);
Example:
$_POST = array('var_1' => 1234, 'var_2' => 'another variable');
extract($_POST);
echo $var_1.' '.$var_2;
Outputs:
1234 another variable
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)
Yeah. You just need to acces like $pass = $_POST['pass']
:).
精彩评论