ajax得到的数据是后台传送数据的整个网页信息,为什么不是传的数据 [ 新手入门 ]
在index.php中,达到了$dataList数据,最后一句是这个,echo json_encode($dataList); 然后在另一个php中,我调用了ajax方法来获得数据
.$(document).ready(function(){
$('#sendMessage').click(function (){
$.ajax({
url:'<?php echo Yii::app()->createUrl("export/index");?>',
success: function (data) {
var returnResult = data;
//var resultMap = eval(returnResult);
//alert(returnResult);
console.log(returnResult);
//console.log(resultMap);
//initMap_a(result);//向地图中添加marker
}
});
});
});
但是出现了很奇怪的事情,得到的信息是index.php的网页信息,而不是里面的数组信息
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="en">
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="/TemplateSite/css/screen.css?20141115" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/TemplateSite/css/print.css?20141115" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="/TemplateSite/css/ie.css?20141115" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/TemplateSite/css/main.css?20141115" />
<link rel="stylesheet" type="text/css" href="/TemplateSite/css/form.css?20141115" />
<link rel="stylesheet" type="text/css" href="/TemplateSite/css/button.css?20141115" />
<link rel="stylesheet" type="text/css" href="/TemplateSite/assets/2dc526a8/mbmenu.css" media="screen" />
<script type="text/javascript" src="/TemplateSite/assets/25b64e04/jquery.js"></script>
<title>My Web Application - Export</title>
</head>
<body>
<div class="container" id="page">
<div id="header">
<!--<div id="logo" style="display:inline-block;">My Web Application</div>-->
<div class="header_info">
<a href="/TemplateSite/index.php?r=site/changeLanguage&lang=en">English</a> </div>
</div><!-- header -->
<div id="menu">
<div id="nav-container">
<div id="nav-bar">
<ul id="nav">
<li><a href="/TemplateSite/index.php?r=site/index"><span>首页</span></a></li>
<li><a href="/TemplateSite/index.php?r=site/page&view=about"><span>关于</span></a></li>
<li><a href="/TemplateSite/index.php?r=site/contact"><span>联系我们</span></a></li>
<li><a href="/TemplateSite/index.php?r=site/login"><span>登录</span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo1"><span>demo </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo2"><span>demo2 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo3"><span>demo3 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo4"><span>demo4 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo5"><span>demo5 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo6"><span>demo6 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo7"><span>demo7 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo8"><span>demo8 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo9"><span>demo9 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo10"><span>demo10 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo11"><span>demo11 </span></a></li>
<li><a href="/TemplateSite/index.php?r=site/demo12"><span>demo12 </span></a></li>
<li class="last"><a href="/TemplateSite/index.php?r=export/admin"><span>test</span></a></li>
</ul></div></div> </div><!-- mainmenu -->
<!-- breadcrumbs -->
<br><br>
<div id="content">
[{"BaiduLat":"31.262788","BaiduLon":"121.630306"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"},{"BaiduLat":"31.263184","BaiduLon":"121.630395"}]</div><!-- content -->
<div class="clear"></div>
<div id="footer">
Copyright © <br/>
All Rights Reserved.<br/>
</div><!-- footer -->
</div><!-- page -->
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
$("#nav li").hover(
function () {
if ($(this).hasClass("parent")) {
$(this).addClass("over");
}
},
function () {
$(this).removeClass("over");
}
);
});
/*]]>*/
</script>
</body>
</html>
有谁知道这是怎么回事吗?怎么改才能之传数据 或者怎么取出这个网页信息里面的数据
共 5 条回复
-
把
ExportController
内actionIndex()
里面的return $this->render('index');
换成
return $this->renderPartial('index');
试试。
共 2 条回复dingjj2010 回复于 2016-01-22 09:46 回复赞,这个方法是yii自带的方法。 如果想直接用php自带的可以直接die(返回的数组);
@dingjj2010 其实这样写烦了,直接url访问控制器中的方法,没有必要取访问view的渲染
fang 觉得很赞
fang
注册时间:2016-01-15
最后登录:2016-10-20
在线时长:5小时0分
最后登录:2016-10-20
在线时长:5小时0分
- 粉丝0
- 金钱290
- 威望0
- 积分340