php jquery ajax怎么把php文件里面的字符返回完了?

2025-03-01 14:58:01
推荐回答(2个)
回答1:

新建一个页面b.php,ajax请求这个页面 ,b.php用来文件流来读取aa.php 里面的文本,然后b.php返回这个文件流的数据

$(document).ready(function(){
$(":button").click(function(){
$.ajax({
url:'b.php',
type:'get',
data: 'do=test&name=必优博客',
success:function(responseText){
alert(responseText);
$("#aa").html(responseText);
}
});
});
});

b.php
$path = "aa.php"
<%php
$file_handle = fopen($path, "r");while (!feof($file_handle)) { $line = fgets($file_handle); echo $line;}
fclose($file_handle);

%>

个人意见

回答2:

$(document).ready(function(){
$(":button").click(function(){
$.ajax({
url:'aa.php',
type:'get',
data: 'do=test&name=必优博客',
dataType:'text',
success:function(responseText){
alert(responseText);
$("#aa").html(responseText);
}
});
});
});

如果还不行的话把php里的那个header去掉看看