The JSON data post to PHP, but in PHP inside $_post get not, I (' id ') also get not, $_request also get not, can look under the AJAX ContentType set data type is what, PHP pairs of type such as Text/xml or Soap or Application/octet-stream and other content can not be resolved, the original PHP is only recognized by default application/ X-www.form-urlencoded the standard data type, we just set the Ajax contenttype to application/x-www.form-urlencoded, or use the file_get_ Contents ("Php://input"). Now we are looking at how the I () method in TP is done?
function I ($name, $default = ", $filter =null) {if (Strpos ($name, '. ')) {//Specify the parameter source//determine if the parameter $name is included. List ($method, $name) = Explode ('. ', $name, 2); If the include. Number is separated by the. Number and assigned to $method and $name}else{//default to Auto-judgment//if not. Number $method = ' param '; } switch (Strtolower ($method)) {//converts $method to lowercase//if $method is get, then $input is $_get case ' get ': $input =& Amp $_get;break; If $method is get, then $input is $_post case ' POST ': $input =& $_post;break; If put, the original data of the post is transferred to the $input case ' put ': Parse_str (file_get_contents (' Php://input '), $input); If it is param case ' param '://Judge $_server[' request_method ' switch ($_server[' Request_method ') ] {//If it is post, then the content of $input is $_post's content case ' POST ': $input = $_post; Break If put, the content of input is the contents of the put. Case ' put ': parse_str (file_get_contents (' Php://input '), $input); Break Defaults to $_get content default: $input = $_get; } break; If $method is request, then $input is $_request case ' REQUEST ': $input =& $_request; Break If $method is a session, then $input is $_session case ' session ': $input =& $_session; Break If $method is a cookie, then $input is $_cookie case ' cookie ': $input =& $_cookie; Break If $method is server, then $input is $_server case ' server ': $input =& $_server; Break If $method is GLOBALS, then $input is $globals case ' GLOBALS ': $input =& $GLOBALS; Break The default return null Default:return null; }/** * So far, all the variables have been taken, based on the need for the parameters passed in (front of the first parameter.). The following is the contents of the return variable. **///If $name is empty, that is, the first parameter of I () is empty after the if (empty ($name)) {//Get all variables//acquired variables $input all copied to $data $data = $input; Array_walk_recursiVe-each member of the array recursively applies the user function//$data the key value as the first parameter of the FILTER_EXP function, and the key name as the second argument//if the key value of the $data contains or or exp, the characters are automatically appended with a space Array_walk_recursive ($data, ' filter_exp '); Determine whether the filter parameters, if any, directly using the filter method, if not, use the filter method in the configuration $filters = Isset ($filter)? $filter: C (' default_filter '); if ($filters) {$filters = explode (', ', $filters); Apply each method in the filter parameter to the $data foreach ($filters as $filter) {//To filter each value of $data using $filters $d ATA = array_map_recursive ($filter, $data); Parameter Filter}}}elseif (Isset ($input [$name])) {//value operation $data = $input [$name]; Is_array ($data) && array_walk_recursive ($data, ' filter_exp '); $filters = Isset ($filter)? $filter: C (' default_filter '); if ($filters) {$filters = explode (', ', $filters); foreach ($filters as $filter) {if (function_exists ($filter)) {$data = Is_array ($data) ?Array_map_recursive ($filter, $data): $filter ($data); Parameter filtering}else{$data = Filter_var ($data, Is_int ($filter)? $filter: filter_id ($filter)); if (false = = = $data) {return isset ($default)? $default: NULL; }}}}}else{//variable default value $data = Isset ($default)? $default: NULL; } return $data;}
From the source code we can see that the $method of the I method is divided into get, post, put, Param, when the Ajax contenttype is not a standard type, when we accept the value can be written
I (' put.id ')
You'll be able to receive the value normally.
thinkphp I () method does not get Ajax pass-through value