Hi all,
I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns it as the responseText. I want to attach that object to the document (or anywhere else that would allow me to access it later), and to do that, I THINK I need to eval it because it's just a string otherwise.
My problem is as soon as I execute a line such as:
eval(e.response Text);
JS seems to halt! I can put an alert immediately after the eval and it will never execute.
I've tried several ways to do this, including putting the whole assignment statement in the PHP response, just the JS object and then assigning a JS var to the result of the eval statement . .
Ex: (PHP output):
document.my_dat a = {my_prop: 'hello world', my_array: [1,2,2]};
(the above would be evaled like this:)
eval(my_ajax_re sponse.response Text);
(I've also tried this:) (PHP output):
{my_prop: 'hello world', my_array: [1,2,2]}
(the above would be evaled like this:)
document.my_dat a = eval(my_ajax_re sponse.response Text);
Again, either way, it seems that JS halts execution as soon as I run an eval like this. I can put an alert right after the eval and it is not called. I don't get any JS errors, either!
Am I approaching this horribly wrong? I can get a simple eval example to work:
(PHP output):
alert('hello world');
(the above is evaled like this:)
eval(my_ajax_re sponse.response Text);
And the above works. It just seems like my attempt to assign the result of the eval to something on the page causes problems, but this is exactly what I need to do . . . Any help would be greatly appreciated!
I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns it as the responseText. I want to attach that object to the document (or anywhere else that would allow me to access it later), and to do that, I THINK I need to eval it because it's just a string otherwise.
My problem is as soon as I execute a line such as:
eval(e.response Text);
JS seems to halt! I can put an alert immediately after the eval and it will never execute.
I've tried several ways to do this, including putting the whole assignment statement in the PHP response, just the JS object and then assigning a JS var to the result of the eval statement . .
Ex: (PHP output):
document.my_dat a = {my_prop: 'hello world', my_array: [1,2,2]};
(the above would be evaled like this:)
eval(my_ajax_re sponse.response Text);
(I've also tried this:) (PHP output):
{my_prop: 'hello world', my_array: [1,2,2]}
(the above would be evaled like this:)
document.my_dat a = eval(my_ajax_re sponse.response Text);
Again, either way, it seems that JS halts execution as soon as I run an eval like this. I can put an alert right after the eval and it is not called. I don't get any JS errors, either!
Am I approaching this horribly wrong? I can get a simple eval example to work:
(PHP output):
alert('hello world');
(the above is evaled like this:)
eval(my_ajax_re sponse.response Text);
And the above works. It just seems like my attempt to assign the result of the eval to something on the page causes problems, but this is exactly what I need to do . . . Any help would be greatly appreciated!
Comment