How does php receive the ajaxpost form? A.html
Var params = $ ("# form1"). serialize ();
$. Ajax ({
Type: "post ",
ContentType: "application/text ",
Data: params,
DataType: "json ",
// DataType: "binary ",
Async: false,
Timeout: 30000,
Url: '1. php ',
Success: function (data ){
// Process data
Var s = eval (data );
Alert (s. a + ''+ s. B );
},
Error: function (x, e ){
// Alert (x. readyState );
Alert (e );
}
});
-------------------------------
1. php
$ Db = new mysqli ('localhost', 'adb', 'winst', 'test ');
Mysqli_query ($ db, "set character set 'utf8 '");
$ Arr =$ _ REQUEST;
$ Vnameid = $ arr ['username'];
$ Vtele = $ arr ['telphone'];
$ Query = "insert into cardvip (namevip, tel) VALUES ('" + $ vnameid + "', '" + $ vtele + "')";
$ Db-> query ($ query );
$ Data = json_encode (array ('a' => $ vnameid, 'B' => $ vtele ));
Echo $ data;
?>
If $ vnameid = 'username ';
$ Vtele = 'telphone ';
1. html alert (s. a + ''+ s. B); correctly displayed.
The post data is not received.
Reply to discussion (solution)
Comment out dataType: "json"
Alert (s. a + ''+ s. B); changed to alert (data );
1. php
Print_r ($ _ POST );
Exit;
Use this change for debugging
Comment out dataType: "json"
Alert (s. a + ''+ s. B); changed to alert (data );
1. php
Print_r ($ _ POST );
Exit;
Use this change for debugging
No problem with the returned data,
$ Arr =$ _ REQUEST;
$ Vnameid = $ arr ['username'];
$ Vtele = $ arr ['telphone'];
I mean $ vnameid cannot obtain post data
$ Vnameid = $ arr ['username']; the value cannot be obtained?
$ Vnameid = $ arr ['username']; the value cannot be obtained?
Well, the value cannot be obtained.
If a.html uses url: '1. php? '+ Params,
You can get the value. what is the problem?
Your ajax parameter dataType: "json", which transmits serialized data.
Remove dataType: "json ".
Did you do what I said?
Did you do what I said?
A.html
Var params = $ ("# form1"). serialize ();
$. Ajax ({
Type: "post ",
ContentType: "application/text ",
Data: params,
Async: false,
Timeout: 30000,
Url: '1. php ',
Success: function (data ){
// Process data
Alert (data );
},
Error: function (x, e ){
// Alert (x. readyState );
Alert (e );
}
});
-----------------------------------
1. php
$ Arr =$ _ REQUEST;
$ Vnameid = $ arr ['username'];
$ Vtele = $ arr ['telphone'];
Echo $ vnameid;
?>
Still cannot get the post value
ContentType: "application/text ",
Remove this. Is there this MIME?
Delete contentType: "application/text ",
OK. Just remove contentType: "application/text ".