jquery ajax请求php,但是却连php源代码都返回了,怎么回事啊????

jqueryajax请求php,但是却连php源代码都返回了,怎么回事啊?????(不用jquery,用js的ajax却可成功echo!!),还有,type设成html,... jquery ajax请求php,但是却连php源代码都返回了,怎么回事啊?????(不用jquery,用js的ajax却可成功echo!!),还有,type设成html,也是返回整个代码,json也是,格式花了的json_encode,关键是,为什么全是把整个代码给返回了,而不是只返回echo的,请高手帮帮忙
$.ajax({
type: "POST",
url: "test.php",
dataType: "html",
data: {"user":"nice","pass":"sj"},
success: function(data){
$("#test").html(data);
alert(data);
},
error:function(){
alert("F");
return false;
}
});

<?php
$arr["name"]="sss";
$arr["di"]="kkk";
$j_arr=json_encode($arr);
echo $j_arr;
echo "sfdsdfsfdsfds";
?>
这是代码,整个源码全返回,type如果改成json,就会出错,因为返回的是代码,不是json
展开
 我来答
Zjmainstay
2012-06-23 · 知道合伙人互联网行家
Zjmainstay
知道合伙人互联网行家
采纳数:580 获赞数:1129
http://www.zjmainstay.cn

向TA提问 私信TA
展开全部
用了你的源码做测试,没发现问题,返回都正确,这是我测试的源码。
//ajax.test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$.ajax({
type: "POST",
url: "test.php",
dataType: "html",
data: {"user":"nice","pass":"sj"},
success: function(data){
$("#test").html(data);
alert(data);
},
error:function(){
alert("F");
return false;
}
});
});
</script>
<div id="test"></div>
</body>
</html>

//test.php
<?php
$arr["name"]="sss";
$arr["di"]="kkk";
$j_arr=json_encode($arr);
echo $j_arr;
echo "sfdsdfsfdsfds";
?>

//返回
1.alert({"name":"sss","di":"kkk"}sfdsdfsfdsfds)
2.{"name":"sss","di":"kkk"}sfdsdfsfdsfds
百度网友0c90796
2012-06-12 · TA获得超过1611个赞
知道大有可为答主
回答量:2638
采纳率:0%
帮助的人:1064万
展开全部
php页面,除了echo的代码,

其他的静态化代码都会被输出,比如

<p>1</p>
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
嘿嘿2202
2012-06-25 · 超过17用户采纳过TA的回答
知道答主
回答量:57
采纳率:0%
帮助的人:15.2万
展开全部
$j_arr=json_encode($arr);这是返回json数据格式,去掉试一下
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
caiaolin
2012-06-12 · TA获得超过664个赞
知道小有建树答主
回答量:621
采纳率:0%
帮助的人:450万
展开全部
给你一个例子
js==================================
$.ajax({
type: "post",
url: "xxx.php",
data: "id=" + id,
timeout: 1000,
error: function(){
alert("error");
},
success: function(msg){
alert(msg);
}
});

xx.php========================================
echo "1234";
exit();
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wangziyu753
2012-06-12
知道答主
回答量:19
采纳率:0%
帮助的人:15.1万
展开全部
源码发来看看
追问
$.ajax({ 
type: "POST",
url: "test.php",
dataType: "html",
data: {"user":"nice","pass":"sj"},
success: function(data){
$("#test").html(data);
alert(data);
},
error:function(){
alert("F");
return false;
}
});

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式