Here is my js code.
....
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");
}
})
Server side.
$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);
After that in client side I’ve recieved city list + html. Something like this.
..."Young America" [20292]=> string(10) "Zanesville" } <html><head>......
Why is HTML transfered ?
This article http://book.cakephp.org/1.1/view/316/Helpers says you should use the ajax render layout:
Another page full of helpful articles on ajax and cake php is this one:
http://ahsanity.wordpress.com/2007/02/23/get-started-with-ajax-in-cakephp/