String#evalJSON throwing a TypeError
Reported by Chris Henry | May 29th, 2008 @ 09:17 PM | in 1.6.1
I'm using prototype in conjunction with Extjs to build out an Ajax-driven app. I'm noticing that occasionally there will be Ajax Requests that will occasionally not complete. After some investigation, I found that when I made the call to String#evalJSON, it will throw a TypeError with the following message :
transport.responseText has no properties.
When this happened, I use firebug to log both the error and the
transport object. When I inspect the transport object,
transport.responseText is definitely there, and well-formed.
Here's some sample code:
new Ajax.Request(url, {
method : 'post',
parameters : params,
onComplete : function(transport) {
var myJSON = jsonTransport(transport);
//do stuff with myJSON
}
});
function jsonTransport(transport) {
try {
return transport.responseText.evalJSON();
} catch (e) {
console.log(e, transport)
}
}
Comments and changes to this ticket
-
Juriy Zaytsev May 29th, 2008 @ 10:25 PM
- → State changed from new to bug
How exactly does json response look? #evalJSON is actually supposed to throw error if json can not be evaluated.
-
Juriy Zaytsev May 29th, 2008 @ 10:25 PM
- → State changed from bug to new
-

Chris Henry May 29th, 2008 @ 10:39 PM
Most often, we're polling the server for small bits of information, so a very common example is :
{"inboxCount":1,"nags":[]}
We're using PHP 5's json_encode on the server.
-
Juriy Zaytsev May 29th, 2008 @ 11:30 PM
- → Milestone changed from to 1.6.1
- → State changed from new to bug
-
Tobie Langel May 30th, 2008 @ 01:29 AM
You should be using the `responseJSON` property of the response object.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
