How does PHP receive javascriptPOST data? $ (Document ). ready (function () & nbsp ;{& nbsp; & nbsp ;$ (# submit ). click (function () {username & nbsp; 1233; password & nbsp; 1233; valc & PHP how to receive javascript POST data?
$(document).ready(function() {
$("#submit").click(function(){
username = 1233;
password = 1233;
valc = 1233;
//password = hex_md5(hex_md5(password)+valc);
//password = hex_md5(password + valc);
var data = new Object();
data.j_username=username;
data.j_password=password;
data.j_valcode=valc;
alert(password);
$.ajax({
url : 'http://127.0.0.1/test/simulation.php',
type : "post",
dataType : "jsonp",
jsonp : "jsonp",
data:data,
})
})
});
In the above jsp code, post should be in the jsonp format. how can I receive and print these values in php?
The code has been modified to facilitate debugging ~
There is another problem... changing the URL without changing the code
Why is the POST data different when it is changed to an incorrect URL or a correct URL?
Correct:
Incorrect:
Please also explain
------ Solution --------------------
Jsonp is the returned format, not the previous data format of Post. Jsonp is used only for cross-origin requests.
The same is true for how PHP receives Post data from other pages.
------ Solution --------------------
Rather than accepting data, you cannot see the content printed by php.
$.ajax({
url : './simulation.php',
type : "post",
dataType : "jsonp",
jsonp : "jsonp",
data:data,
})
Rewrite
$.ajax({
url : './simulation.php',
type : "post",
data:data,
success : function(d) {
alert(d);
}
})
In simulation. php
Print_r ($ _ POST );
You can see what is passed in.