Monday, July 18, 2011

JQuery AJAX error function jqXHR.responseText is a string

The jqXHR.responseText is a string although it looks like JSON.

E.g. "{"Message":"domain\\a_fkf has no access","StackTrace":" at CustomAppTaskListRetriever.GetNumTasks(String userID) in C:\\Documents and Settings\\Visual Studio 2008\\Projects\\Retriever.cs:line 45\r\n at MyWorkbox.WorkboxService.GetNumTasks(String appID) in C:\\Documents and Settings\\Visual Studio 2008\\Projects\\WorkboxService.asmx.cs:line 32","ExceptionType":"System.Exception"}"

Here's how you can "parse" it. Not very elegant, but that's the best I can find:

TaskList.prototype.GetTaskItems = function() {
var t = this;
success: function(data) {...},
error: function(jqXHR, textStatus, errorThrown) {
eval("var responseJSON = " + jqXHR.responseText + ";");

No comments:

Post a Comment