2011-04-26 50 views
0

此代碼產生語法錯誤..但我無法弄清楚什麼是錯的?eval() - 語法錯誤

alert(eval('('+this.responseText+')')); 

編輯:

 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); 
+0

可能,你的迴應文本不是有效的JavaScript ... – Vishwanath 2011-04-26 06:38:04

+2

什麼價值responseText的? – 2011-04-26 06:38:17

+0

當然是! :D作出回答 – clarkk 2011-04-26 06:39:02

回答

1

你將不得不檢查responseText是否是實際上有效的JavaScript。你確定你不想只是顯示而不是執行它的字符串:

alert(this.responseText); 

我要告訴你,除非你有在哪裏這個responseText是來自總控制,這是一個通過以下途徑飛行的C130飛機:-)

0
a= eval("("+this.responseText+")"); 
alert(a); 

嘗試上述代碼部分。希望它會有所幫助。

0

括號是原因。嘗試這個。

alert(eval(this.responseText)); 
1

_this.rtn_func(EVAL( '(' + this.responseText + ')'),_this.rtn_obj,_this.rtn_scope);

eval直接執行腳本。如u有響應像12 + 3 + 4

其形式

eval('(12 + 3 + 4)') 

這應該是工作。難道ü嘗試這樣

其他明智的,如果響應文本作爲返回函數名或其他一些字符串數據顯示其錯誤

eval('(formdata())')