js如何用ajax传递变量给php
<?php$wdurl=$_GET['url'];$temp=explode('<divid="player">',file_get_contents($wdurl));...
<?php
$wdurl = $_GET['url'];
$temp=explode('<div id="player">',file_get_contents($wdurl));
$temp1=explode('<iframe border=',$temp[1]);
echo $temp1[0];
?>
<script>
var pp_serverurl=pp_serverurl.replace(/baiduhd/g,"bdhd").replace(/youku_new/g,"youku");
var pp_play=decodeURIComponent(pp_play);
document.write ( "player:["+pp_serverurl+"]<br>url:["+pp_play.replace(/\+\+\+/g, "#").replace(/\+\+/g, "$").replace(/http:\/\/player.youku.com\/player.php\/sid\//g,"").replace(/\/v.swf/g,"")+"]");
</script>
这段代码中如何ajax或者post把js的pp_serverurl和pp_play两个变量传递给php? 展开
$wdurl = $_GET['url'];
$temp=explode('<div id="player">',file_get_contents($wdurl));
$temp1=explode('<iframe border=',$temp[1]);
echo $temp1[0];
?>
<script>
var pp_serverurl=pp_serverurl.replace(/baiduhd/g,"bdhd").replace(/youku_new/g,"youku");
var pp_play=decodeURIComponent(pp_play);
document.write ( "player:["+pp_serverurl+"]<br>url:["+pp_play.replace(/\+\+\+/g, "#").replace(/\+\+/g, "$").replace(/http:\/\/player.youku.com\/player.php\/sid\//g,"").replace(/\/v.swf/g,"")+"]");
</script>
这段代码中如何ajax或者post把js的pp_serverurl和pp_play两个变量传递给php? 展开
展开全部
two.php
<?php
if($_GET){
file_put_contents("d:/a.txt", $_GET['pp_serverurl'] , FILE_APPEND);
}
?>
<script type="text/javascript">
var pp_serverurl=1;
var pp_play=2;
submit(pp_serverurl,pp_play);
var xmlHttp;
function submit(pp_serverurl,pp_play){
set_XMLHttpRequest();
xmlHttp.open("GET","two.php?pp_serverurl="+pp_serverurl+"&pp_play="+pp_play,true);
xmlHttp.send(null);
}
function set_XMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
</script>
如果你只想把值传给php,这样就够了,希望对你有用。
更多追问追答
追问
追答
ajax不是打开php文件,而是把值传给php文件,php echo出的值是一个返回值,之前我的代码是把值存放在了d:/a.txt文件中了,只是传值,没有返回值。
a.php
<?php
if($_GET){
echo $_GET['pp_serverurl'];
file_put_contents("d:/a.txt", $_GET['pp_serverurl'] , FILE_APPEND);
}
?>
a.html
<script type="text/javascript">
var pp_serverurl=1;
var pp_play=2;
submit(pp_serverurl,pp_play);
var xmlHttp;
function submit(pp_serverurl,pp_play){
set_XMLHttpRequest();
xmlHttp.open("GET","a.php?pp_serverurl="+pp_serverurl+"&pp_play="+pp_play,true);
xmlHttp.onreadystatechange=callback;
xmlHttp.send(null);
}
function set_XMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function callback(){
if(xmlHttp.readyState == 4){
var message = xmlHttp.responseText;
alert(message);//这是php输出的返回值
}
}
</script>
在php环境下运行a.html即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询