I have a javascript pattern for AJAX that looks like this (using the prototype.js library):
new Ajax.Request('/some/url/that/reposonds/with/json?queryParam=' + encodeURIComponent(queryParam),
{
onSuccess: function(request) {
eval("var data = " + request.responseText);
document.getElementById("value").innerHTML = data.value;
document.getElementById("status").innerHTML = data.status;
},
onException: function(request, exception) {
alert("ERROR: " + exception);
}
});
I use JSON as the AJAX reponse format instead of XML, so we always call eval() on the reponse. I've found that if I return arrays of data I can do something like this:
var data = eval(request.responseText);
And IntelliJ is happy. But mostly I return javascript objects and I've found I need to put the "var data = " instead the eval call, as in the above example, or it will not work correctly. In these cases, I get a lot of warnings from IntelliJ about an unresolved variable every time I use the variable declared inside the eval().
I realize analyzing eval() calls is a huge hassle from a static analysis perspective, but if you correctly handle simple variable declarations that would be a great step forward.