thinkphp中用ajax的问题 想做个二级联动

WBOY
Release: 2016-06-20 12:27:57
Original
1179 people have browsed it

public function  Billing()
{
   //后台ajax验证
   $result = array();
   $cate['S_Customer'] =$_POST['S_Customer'];
   $result = M('Customer')->where( $cate)->field('phone,c_name')->select();
   $this->ajaxReturn($result,"json");
  $this->display();
}

为什么显示的只是数组,而我原网页不显示了,,,难道我的输出有问题?


只出现[{"phone":"13802149988","c_name":"\u5f20\u4e09"},{"phone":"13802144455","c_name":"\u674e\u56db"}],F12检查,发现页面上也就只有这数组,,其他东西都没有。。


<script> <br /> $('#S_Customer').change(function(){ <br /> <br /> $.ajax({ <br /> url:"{:U('Crud/Billing')}", <br /> type:'post', <br /> data:{ <br /> name:$('#S_Customer').val() <br /> }, <br /> dataType:'json', <br /> success:function(data){ <br /> if(data.success) <br /> { $('#phone').html(data.msg) } <br /> <br /> else {alert("失败")} <br /> <br /> <br /> }, <br /> error:function(data){alert(data.status);} <br /> }) <br /> <br /> <br /> }) <br /> <br /> <br /> </script>


怎么样才能实现二级联动呢。。


回复讨论(解决方案)

求大神出答案!!。。

$this->ajaxReturn 里面有个exit

$this->ajaxReturn 里面有个exit


嗯,,然后呢,我是初学者,所以还是不明白您的意思,详细点。。谢了!

thinkphp 的 ajax 响应默认是返回 json 的
再说你也通知 $.ajax 返回的是 json 替我解码(dataType:'json',)
但是你的返回结果中并没有 success 和 msg 项
而 $('#phone').html(data.msg) 中,data.msg 的内容应该是 html 代码

不要随意的去抄人家的代码,要理解为什么要那么写

thinkphp 的 ajax 响应默认是返回 json 的
再说你也通知 $.ajax 返回的是 json 替我解码(dataType:'json',)
但是你的返回结果中并没有 success 和 msg 项
而 $('#phone').html(data.msg) 中,data.msg 的内容应该是 html 代码

不要随意的去抄人家的代码,要理解为什么要那么写


谢谢指点!
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!