Reputation: 1
this code produce an syntax error.. but I can't figure out what is wrong?
alert(eval('('+this.responseText+')'));
EDIT:
var _this = this;
this.resource.open('POST', uri, true);
this.resource.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.resource.onreadystatechange = function(){
if(this.readyState == 4){
_this.clear_timeout();
if(_this.loader){
Loader.dstr();
}
if(_this.rtn_func){
_this.rtn_func(eval('('+this.responseText+')'), _this.rtn_obj, _this.rtn_scope);
}
}
};
this.resource.send(get_str);
Upvotes: 0
Views: 2519
Reputation: 3106
_this.rtn_func(eval('('+ this.responseText + ')'), _this.rtn_obj, _this.rtn_scope);
The eval is directly execute the script. Such as u have Response like 12 + 3 + 4
its form
eval('(12 + 3 + 4)')
this should be work. Are u try like that
Other wise if response text as return function name or else some string data its show error
eval('(formdata())')
Upvotes: 1
Reputation: 11844
a= eval("("+this.responseText+")");
alert(a);
Try the above code part. Hope it will help.
Upvotes: 0
Reputation: 882426
You would have to check whether or not responseText
is actually valid Javascript. Are you sure you didn't want to just display the string rather than execute it:
alert(this.responseText);
I should tell you that, unless you have total control over where this responseText
is coming from, that's a hole big enough to fly an C130 aircraft through :-)
Upvotes: 1