My JS Is:
$(InitFavorite);
function InitFavorite(){
var jList = $(".favourite_link");
var ids_to_check = {};//new Array();
$.each(jList, function () {
var id = this.id;
var object = id.split("_");
if (!ids_to_check[object[1]]) {
ids_to_check[object[1]] = [];
}
ids_to_check[object[1]].push(object[0]);
});
//console.log(ids_to_check);
$.ajax({
type: 'POST',
url: '/user/subscription/favourite-listing',
data: ids_to_check,
dataType: 'json',
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
error: function() {
alert(1);
},
success: function() {
alert(2);
/*$each(returned_values, function() {
alert('boo开发者_如何学Pythonm');
});*/
}
});
}
From the ajax call, the following data is returned:
{"env":"development","loggedIn":true,"translate":{}}{"Playlist":{"10":"Stop Recieving Updates For This Playlist"},"Clip":{"26":"Recieve Updates For This Clip","27":"Recieve Updates For This Clip","28":"Recieve Updates For This Clip","29":"Stop Recieving Updates For This Clip","30":"Recieve Updates For This Clip"}}
However, success is never triggered, just error, despite there being no header and json being put out as the header (via zend framework).
Ideas?
The quoted JSON is invalid, there can be only one top level object, which must then contain everything else (as properties). Details on the JSON site.
{"env":"development","loggedIn":true,"translate":{}}{"Playlist"...
^-- here's the error
It's always a good idea to look at the errorThrown
parameter to the error function. In this case, it would flag up the error from the JSON parser ("Unexpected token: {" in Chrome, "Expected ';'" in IE, "SyntaxError: JSON.parse" in FF, etc.).
精彩评论