Home  >  Article  >  Backend Development  >  PHP怎么接收javascript POST的数据

PHP怎么接收javascript POST的数据

WBOY
WBOYOriginal
2016-06-13 12:01:421065browse

PHP如何接收javascript POST的数据?

$(document).ready(function() {<br />    $("#submit").click(function(){<br />		username = 1233;<br />		password = 1233;<br />		valc = 1233;<br />		//password = hex_md5(hex_md5(password)+valc);<br />		//password = hex_md5(password + valc);<br />		var data = new Object();<br />		data.j_username=username;<br />		data.j_password=password;<br />		data.j_valcode=valc;<br />		alert(password);<br /> 		$.ajax({<br />			url : 'http://127.0.0.1/test/simulation.php',<br />			type : "post",<br />			dataType : "jsonp",<br />			jsonp : "jsonp",<br />			data:data, <br />			})<br />		})<br />});

上面这段jsp代码,post出去应该是jsonp格式的,请问在php中如何接收并打印出来这些数值?
代码已经改好方便调试~
还有个问题...在代码不改变的情况下,改变URL
当改变成错误的URL时和正确的URL时为什么POST的数据不一样?
正确的:

错误的:

还请解释

------解决方案--------------------
jsonp是返回的格式,不是Post过去的数据格式。跨域才会用到jsonp。
Ajax里Post过去的数据,PHP里怎么接收其它页面的Post数据,这个也一样。
------解决方案--------------------
不是接受不到数据,而是你看不到 php 打印的内容
<br />         $.ajax({<br />            url : './simulation.php',<br />            type : "post",<br />            dataType : "jsonp",<br />            jsonp : "jsonp",<br />            data:data, <br />            })<br />
改写为
         $.ajax({<br />            url : './simulation.php',<br />            type : "post",<br />            data:data, <br />            success : function(d) {  <br />               alert(d);<br />            }<br />         })

simulation.php 中
print_r($_POST);
你就可以看到传入的是什么了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn