Jquery+CakePHP2+ Ajax更新处理操作
2013-06-09 12:37 科屹 阅读(358) 评论(0) 编辑 收藏 举报参考文章出处:http://blog.xao.jp/blog/cakephp/one-of-the-simple-way-for-using-ajax-in-cakephp/
最近一直在做cakephp方面的东西,正好用的ajax,在网上查了很多资料,在这里给遇到同样困难的人一些帮助。
直接上代码
phpCode
1 public function ajax_area(){ 2 $this->layout = null ;// 3 //判断请求为ajax请求 4 if ( $this ->RequestHandler->isAjax()){ 5 $this->autoRender = false;//这个必须设定 6 .....这块写获取数据的code,在这个中,可以用echo、print_r将你需要的数据传递到js中.... 7 } 8 }
JsCode
1 function ajax_js() { 2 $.ajax( { 3 type: 'POST', 4 url:'/../AddController/ajax_area', 5 data: {"num" : 10}, 6 success: function(data, dataType) { 7 .......jscode.... 8 }, 9 error: function (HMLhttpRequest, textStatus, errorThrown) { 10 alert(textStatus + " : " + errorThrown); 11 } 12 } ); 13 }
写的比较简单,有不明白的,可以留言,我尽量帮助。