问题描述
你好朋友...
我刚刚开始研究php.我觉得这是一个很好的语言,但由于我是新手,所以有些时候我被卡住了.
我的JavaScript代码
Hello friends...
I have just started working on php. It''s a very good lang as I''m feeling but some point I get stuck as I''m new to this.
My javascript code
var pv = $("#txtStart").val();
var av = $("#txtStartNextLevel").val();
var au = $("#fileStartPlay").val();
alert(pv+" "+av+" "+au);
var myau = au.split(''\\'');
$.ajax({
type:"POST",
url:php_url,
data:"{startPoint:"+pv+"nextLevelPoint:"+av+"audioFile:"+myau[myau.length-1]+"}",
contentType:"application/json",
dataType:"json",
success:function(){
alert("done");
},
error:function(){
alert(response);
}
});
我的PHP代码.
My PHP code.
<?php
if(file_exists("Text.txt"))
{
$fileName = "Text.txt";
$fh = fopen($fileName,"a")
$Starts = $_POST["startPoint"];
$NextLevel = $_POST["nextLevelPoint"];
$AudioFileName = $_POST["audioFile"];
$code .=$Starts."*".$NextLevel."_1*".$AudioFileName."\"";
fwrite($fh,$code);
fclose($fh);
}
?>
当我运行它时,它会执行,但不会在变量 $ Starts,$ NextLevel,$ AudioFileName 中写入值.
还有,如果我在
中编写相同的ajax过程 $.post(php_url,{startPoint:pv,nextLevelPoint:av,audioFile:myau [myau.length-1]},function(data){}); 可以正常工作并将其内容写入文件.
而且当我使用post方法时,它不应在地址栏中显示我要写入的值.但这两种方法都显示了这些值.
localhost://myphp.php?txtStart = Start& fileStartPlay = aceduos.jpg& txtStartNextLevel = adfd
请指导我缺少的地方.
When I run this it executes but doesn''t write the values in the variable $Starts,$NextLevel,$AudioFileName.
And further if I write the same ajax procedure in
$.post(php_url,{startPoint:pv,nextLevelPoint:av,audioFile:myau[myau.length-1]},function(data){}); this works fine and write the content in the file.
Also As I''m using post method it should not display the values in Address bar what I''m passing to write. But it''s showing those values in both the method.
localhost://myphp.php?txtStart=Start&fileStartPlay=aceduos.jpg&txtStartNextLevel=adfd
Please guide me where I''m lacking...
推荐答案
这篇关于无法使用php执行jquery.ajax操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!