I was missing dataType: 'json', in the js…..
Dave
From: Advantage+ [mailto:movepixels@gmail.com]
Sent: Tuesday, October 16, 2012 3:26 PM
To: cake-php@googlegroups.com
Subject: Upgrade 1.3 -> 2.1.3 Issue
My app 1.3 version was working fine, now slowly upgrading / converting to 2.1.3 and running into an issue with my JSON response.
In 1.3 I clicked "Add to favorite" and the js would update my favorite counter such as Favorites ( 8 ) <- 8 , 9, 10 whatever number of favorite they had saved. Pretty simple.
The JSON response was {"count":5} Using js function: $("a.favorite").live("click", function(){ $(this).toggleClass("not"); $.ajax({ type: "POST", url: $(this).attr('href'), success: function(r){ $('a#fav_count span span').html(r.count); } }); return false;}); Rendered HTML for the counter is:<a id="fav_count" href="/profiles/favorite "><span>Favorites(<span >6</span>)</span></a>I have been using this to return my JSON :
public function _ajaxReturn( $response = null ) {
//original 1.3 version
$this->header('Content-Type: application/json');
//new 2.1.3 version
//$this->RequestHandler->setContent('json', 'application/json');
echo json_encode($response);
exit();
}
But for some reason the Favorite counter no longer updates the number. Getting zero errors, check error log, no js errors. The response still comes back as it did in 1.3 but nothing happens to the number count.
Any ideas anyone?
Thanks,
Dave
No comments:
Post a Comment