Has anyone else noticed that the JS API sometimes returns both a success AND error message, invalidating the JSON and going nuts when the browser tries to eval() it?
{"error":"Unable To Regenerate Metadata For Asset"}{"success":["Metadata field #93701 has been successfully set to \"xyz\" for Asset \"abc\" (#101535)"}
Does anyone know if this has been fixed in a later version? I can't find any reference to it.
I'd pop this one in the bug tracker as it doesn't look intended. It may have completed 2 actions that gave a different result, but should be returning them inside the same JSON string.
As a side note for anyone else who’s interested, I’ve created the following modification, although it won’t work in anything below IE 8 without an additional JSON parser.
function jsonToObj(json)
{
// Make the conversion
var jsonObj = false;
try{
jsonObj = JSON.parse(json);
}catch(e){
jsonObj = {error:'The server returned garbage where JSON was expected. ('+e+') '+json}
}
return jsonObj;
}
This will catch invalid JSON as well as 404 pages and blank pages (for instance from PHP errors).
As a side note for anyone else who’s interested, I’ve created the following modification, although it won’t work in anything below IE 8 without an additional JSON parser.
function jsonToObj(json)
{
// Make the conversion
var jsonObj = false;
try{
jsonObj = JSON.parse(json);
}catch(e){
jsonObj = {error:'The server returned garbage where JSON was expected. ('+e+') '+json}
}
return jsonObj;
}
This will catch invalid JSON as well as 404 pages and blank pages (for instance from PHP errors).
[/quote]
Ash,
FWIW I'm having exactly this issue with a call to setMetadata(). The browser reports an error because invalid JSON is returned, but the metadata is properly set.
I'll try the overloading approach, thanks for the tip.