In my init I have:
$contextSwitch = $this->_helper->getHelper('ForceContext');
$contextSwitch->addActionContext('favourite-listing', 'json')->initContext();
In my controller method I have:
public function favouriteListingAction() {
$newValues = array();
if (isset($_POST['Playlist']) && is_array($_POST['Playlist'])) {
foreach ($_POST['Playlist'] as $key => $value) {
$response = $this->checkAction('Playlist', $value, 0, 1, 'favourite');
$newValues['Playlist'][$value] = $response;
}
}
if (isset($_POST['Clip']) && is_array($_POST['Clip'])) {
foreach ($_POST['Clip'] as $key => $value) {
$response = $this->checkAction('Clip', $value, 0, 1, 'favourite');
$newValues['Clip'][$value] = $response;
}
}
$this->view->favourites = $newValues;
}
However calling this, returns:
{"loggedIn":true,"request":{},"response":{"headersSentThrowsException":true},"translate":{},"favourites":{"Clip":{"726":"<img src=\"\/design\/images\/icon\/subscribe.png\" \/> Add Clip To Favourites","727":
"<img src=\"\/design\/images\/icon\/subscribe.png\" \/> Add Clip To Favourites","728":"<img src=\"\/design\/images\/icon\/subscribe.png\" \/> Add Clip To Favourites","729":
"<img src=\"\/design\/images\/icon\/subscribe.png\" \/> Add Clip To Favourites","730":
"<img src=\"\/design\/images\/icon\/subscribe.png\" \/> Add Clip To Favourites","731":"<img src=\"\/design\/images\/icon\/subscribe.png\" \/> Add Clip To Favourites","732":
"<img src=\"\/design\/i开发者_如何学Pythonmages\/icon\/subscribe.png\" \/> Add Clip To Favourites"}}}
As you can see, its adding slashes, which causes issues. Is there away to stop it doing this?
Possible magic quotes configured on server?
Magic Quotes
To my mind, this behavior is normal, your JSON parser should remove these slashes. I personnaly use the JQuery $.ajax() function for my Ajax projects, you have to set the dataType to JSon (one of my colleague got problem while trying to get the result as text and parsing it in an other way).
$.ajax( ... ,dataType : "json", ...);
If you don't find your problem you could always just run function stripslashes http://php.net/manual/fr/function.stripslashes.php on the data to strip it of its extra slashes.
精彩评论