/    Sign up×
Community /Pin to ProfileBookmark

json deserialized object has ISError Property by default?

In the code below, using prototype library, the Ajax.request returns a set of data which i can see is populated in the var response object.

There is alot of data in the var response object, but the IsError and AppItems object are undefined.

Is there supposed to be an ISError property by default, or would this have to be defined in the AJAX data which is returned?

[CODE]new Ajax.Request(url, {
method: ‘get’,
onSuccess: function(transport) {
// Parse out serialized response
var response = transport.responseText.evalJSON(); // this has many properties but, not IsError
if (response.IsError) {
setResultMessage(response.Message, response.IsError);
return;
}
else
{
// Always start at first page
currentPage = 1;

// Fill the search results
fillSearchResults(resultsTable, response.AppItems); //this response.AppItems is never defined either
return;
}
}
}
); [/CODE]

Thank you for input.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mparker1113authorMay 20.2009 — The link you sent speaks about how to send a request to AJAX, my troubles have to do with the transport.responseText.evalJSON() method, and the object that is created.

I want to know if there is a default IsError property for the object which is returned from that transport.responseText.evalJSON() method, and some possibly some other specifics surrounding that object.
Copy linkTweet thisAlerts:
@toicontienMay 20.2009 — The evalJSON method appears to be added to the String class by Prototype. I believe those properties are there so you can turn any string into a JSON object, and if there was a syntax error in the string, the IsError property would be true:
[CODE]var foo = "my string";
var bar = "{age:13}";

var fooObj = foo.evalJSON();
var barObj = bar.evalJSON();

if (fooObj.IsError) {
alert("foo isn't valid JSON");
}

if (barObj.IsError) {
alert("bar isn't valid JSON");
}[/CODE]


I think that's how it's supposed to be used.
×

Success!

Help @mparker1113 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...