这是我的js代码。无法仅接收来自JQuery的JSON ajax调用
....
var arrayData = {"projectId": projectId, "stateId":stateId};
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "/bidboldly/projects/editproject/",
data: arrayData,
success : function(response) {
alert(response);
},
error: function(){
alert("error");
}
})
服务器端。
$city = $this->City->find('list',array('conditions' =>array('City.status'=>1, 'City.state_id'=>$this->params['url']['stateId']),'fields'=>array('City.id','City.city'),'order'=>array('City.city ASC')));
echo json_encode($city);
之后,在客户端我收到了城市列表+ html。像这样的东西。
..."Young America" [20292]=> string(10) "Zanesville" } <html><head>......
为什么要传输HTML?
您的回音后添加退出:) – jantimon 2012-04-23 22:37:43
你还在剧本中做什么?您是否使用将模板中的任何输出放入模板的框架? ''年轻美国人'[20292] =>字符串(10)“Zanesville”}'看起来并不像JSON(更像'var_dump')。 – 2012-04-23 22:40:14
@Ghommey你在开玩笑吗? :) – emilan 2012-04-23 22:40:23