Menu
I am wondering how possible it is to use eval() to parse javascrpt that is pulled in through ajax(innerHTML)? I have found a few notes about this, such as:
[CODE]var myObj = eval ( xmlhttp.responseText );
I am confused on how to get this working…any ideas, or someone who has done this?
<font size=5>hello world</font>
alert(xmlhttp.responseText)
response = xmlhttp.responseText.indexOf("lo worl")
// would error because this plain text isnt valid javascript syntax
eval(xmlhttp.responseText)
// stuff the response into an array using shorthand
var myArray = [xmlhttp.responseText]
<i>
</i>// in this example, assume that the responseText property contains only the word "myDiv"
// if myDiv exists as an object in the DOM, we could create an object reference with the responseText
var myObj = document.getElementById(xmlhttp.responseText)
it is necessary to understand that the responseText property simply contains text. it isnt "HTML", it isnt "javascript", it isnt an object; it isnt anything except text.[/QUOTE]
eerrr, not really. The responseText [I]might[/I] be a "JSON like" written text, case in which eval() will transform the string text response into a [B]JSON object[/B]...[/QUOTE]
[code=php]
var object = '{"hello":"test"}';
var json = eval(object);
[/code]
is the exact same as[code=php]
var json = {"hello":"test"};
[/code]
eval pretends there never was a variable there, to put it simply. So basically:[code=php]
is the exact same as
var object = '{"hello":"test"}';
var json = eval(object);
[/code][code=php]
[/QUOTE]
var json = {"hello":"test"};
[/code]
eerrr, not really. The responseText [I]might[/I] be a "JSON like" written text, case in which eval() will transform the string text response into a [B]JSON object[/B]...[/QUOTE]
...eval() will[COLOR="Red"]transform the string text[/color] response into a [B]JSON object[/B]...[/QUOTE]
So, basically if it is mixed HTML and javascript, I am out of luck for actually parsing that javascript if it is in the response text, using eval()?[/QUOTE]
xmlHttp.responseText = "[COLOR="Red"]<[/COLOR]font color=red>hello world</font><script>alert('hello world')</script>"
function sethtml(div,content)
{
var search = content;
var script;
<i> </i>while( script = search.match(/(<script[^>]+javascript[^>]+>s*(<!--)?)/i))
<i> </i>{
<i> </i> search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);
<i> </i> if (!(endscript = search.match(/((-->)?s*</script>)/))) break;
<i> </i> block = search.substr(0, search.indexOf(RegExp.$1));
<i> </i> search = search.substring(block.length + RegExp.$1.length);
<i> </i> var oScript = document.createElement('script');
<i> </i> oScript.text = block;
<i> </i> document.getElementsByTagName("head").item(0).appendChild(oScript);
<i> </i>}
<i> </i>document.getElementById(div).innerHTML=content;
}
Hi
I am using eval function to evaluate an ajax response which is nothing but result of a query.
The problem I am facing is that when the result set contains french charachters,eval function breaks.
How can i handle these special charachters in eval??[/QUOTE]
0.1.9 — BETA 6.17