D
Dave
Folks,
There may be a trivial solution to this, but I'm not sure where to
begin...
I am have been writing a relatively simple js using JSON with a
callback. The problem is, the server from which I am pulling the data
may not be all that reliable. I have a setTimeout to accommodate a
404, but on occasion, this server might in fact produce something
other than js. Consequently, the appended function throws a syntax
error. The setTimeout I have will continue to work such that the user
will get some sort of visual cue. But, the syntax errors that may be
produce in the client's browser are annoying (i.e. HTML or SQL errors,
etc. may be returned and appended instead of the js I wanted). Is
there any way to detect if the data appended is in fact NOT js? The
only thing I can think of (but haven't done it yet) is to first append
the returned data into a hidden div, then use toJSONString(), & if the
data are good, append it back to document after first using parseJSON
on it. Eesh. There has to be a better way.
Thanks for any pointers,
Dave
There may be a trivial solution to this, but I'm not sure where to
begin...
I am have been writing a relatively simple js using JSON with a
callback. The problem is, the server from which I am pulling the data
may not be all that reliable. I have a setTimeout to accommodate a
404, but on occasion, this server might in fact produce something
other than js. Consequently, the appended function throws a syntax
error. The setTimeout I have will continue to work such that the user
will get some sort of visual cue. But, the syntax errors that may be
produce in the client's browser are annoying (i.e. HTML or SQL errors,
etc. may be returned and appended instead of the js I wanted). Is
there any way to detect if the data appended is in fact NOT js? The
only thing I can think of (but haven't done it yet) is to first append
the returned data into a hidden div, then use toJSONString(), & if the
data are good, append it back to document after first using parseJSON
on it. Eesh. There has to be a better way.
Thanks for any pointers,
Dave