亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

serializers - The data passed by ajax is a serialized string, why does php accept it as an array?
伊謝爾倫
伊謝爾倫 2017-05-16 13:00:09
0
4
1085

Front-end code:
if(register_flag){ //The registration information is correct

        //alert(typeof($('.register-form').serialize()));
        //序列化的結(jié)果:name=hesisi&account=15223306809&verification-code=2333&password=hss123456&confirm-pwd=hss123456
        $.ajax({
            type : 'POST',
            url : 'php/register.php',
            data : $('.register-form').serialize(),  //序列化的字符串
            success : function(data){
                //window.location.href = "index.html";
            },
            error : function(){
                //錯(cuò)誤信息處理
                console.log();
            }

        });            

    }

php code
require 'config.php';


$data =$_POST;
//name=hesisi&account=15223306809&verification-code=2333&password=hss123456&confirm-pwd=hss123456
$arr = explode("&",$data);
$name_arr = explode("=",$arr[0]);
$account_arr = explode("=",$arr[1]);
$verifcode_arr = explode("=",$arr[2]);
$password_arr = explode("=",$arr[3]);
$confirmpwd_arr = explode("=",$arr[4]);

$name = $name_arr[1];
$account = $account_arr[1];
$verifcode = $verifcode_arr[1];
$password = $password_arr[1];
$confirmpwd = $confirmpwd_arr[1];

$mobile_code = $_SESSION['mobile_code'];

$query = "SELECT * from user WHERE user_account=".$account;
$result = mysqli_query($query);

if($verifcode != $mobile_code){//手機(jī)驗(yàn)證碼錯(cuò)誤
    exit("手機(jī)驗(yàn)證碼錯(cuò)誤!");
    return;
}else if($result){
    exit("改手機(jī)號(hào)已經(jīng)注冊(cè)!");
    return;
}else{
    $insert = "INSERT INTO user(user_name,password,user_account) VALUES(".$name.",".$password.",".$account.")";
    mysqli_query($insert);
    exit("注冊(cè)成功!");
}

The error reported here is that the second parameter of explode() should be of string type, but what I used is array type. The data passed by ajax is of string type. Why does PHP accept the array type through $_POST[]? data has never written php before, please give me some advice, thank you~

伊謝爾倫
伊謝爾倫

小伙看你根骨奇佳,潛力無(wú)限,來(lái)學(xué)PHP伐。

reply all(4)
給我你的懷抱

The parameter you receive is an array,

$data =$_POST;
其實(shí)就是下面的數(shù)組
$data['name']='hesisi';
$data['account']='15223306809';
$data['verification-code']='2333';
...
并不是name=hesisi&account=15223306809&verification-code=2333&password=hss123456&confirm-pwd=hss123456,
你這個(gè)data就是數(shù)組,不是字符串,你不能去explode去切割
習(xí)慣沉默

ajax adds parameter Content-Type: 'text/plain'

If php accepts it, don’t use $_POST, change it to file_get_contents('php://input')

迷茫

With ajax, no matter whether the data you pass to the backend is json or serialized string, it will be parsed into an array form when it reaches the backend.
So

$data =$_POST;

//$data 就是個(gè)數(shù)組啊 
淡淡煙草味

I want to visit the original poster, please look at the url address www.baidu.com?search=keyword&s=key&time=143032423

Do you need to use $_GET when receiving in the background? It is still an array. The key is how $_GET and $_POST work

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template