javascript 中的eval里不能包含AJAX这个单词吗
包括了就会出错
JS中还有没有和EVAL这个函数有一样的功能了

解决方案 »

  1.   

    你的json格式不正确吧,怎么可能不能包含ajaxvar s="{ajax:'内容',AJAX:'AJAX'}"
    var o=eval('('+s+')')//========注意加上括号()
    alert(o.ajax)
    alert(o.AJAX)
    s='["ajax","AJAX","AJAX"]'
    o=eval('('+s+')')
    alert(o)
      

  2.   

    function smileqAjax(url)
    {
    var m_xmlReq=false;
    var m_OnSucceed=function(){};
    var m_OnReading=function(){};
    var m_timer=null; this.Url=url; if(window.XMLHttpRequest)
    {
    m_xmlReq = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)

       try {m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP'); }catch(e)
       {
      try { m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
    }
    } this.OnReading = function(reading) {
    m_OnReading = reading; 
    } this.OnSucceed=function(succeed)
    {
    m_OnSucceed=succeed;
    } this.OnTimeout=function(timeout)
    {
    m_timer=window.setTimeout(timeout,10000);
    } this.invokeServer = function(send_data, method) {
        if (!m_xmlReq) return;
        var thisUrl = this.Url;
        if (this.Url.indexOf("?") > 0)
            thisUrl += "&r=" + (new Date()).getMilliseconds() + "&" + send_data.toString();
        else
            thisUrl += "?r=" + (new Date()).getMilliseconds() + "&" + send_data.toString();
        m_xmlReq.open(method, thisUrl, true);
        if (method == 'POST')
            m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
        m_xmlReq.onreadystatechange = function() {
            if (m_xmlReq.readyState == 1) {
                m_OnReading();
            }
            else if (m_xmlReq.readyState == 4 && m_xmlReq.status == 200) {
                var result = null;
                if (m_xmlReq.responseText != "") {
                   // result = m_xmlReq.responseText;
                    // document.write(m_xmlReq.responseText);
                   eval("result=" + m_xmlReq.responseText);
                }
                m_OnSucceed(result);
                if (m_timer != null) window.clearTimeout(m_timer);
            }
        }
        m_xmlReq.send('');
    }
    } 这是我的代码
      

  3.   

    function smileqAjax(url)
    {
    var m_xmlReq=false;
    var m_OnSucceed=function(){};
    var m_OnReading=function(){};
    var m_timer=null; this.Url=url; if(window.XMLHttpRequest)
    {
    m_xmlReq = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)

       try {m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP'); }catch(e)
       {
      try { m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
    }
    } this.OnReading = function(reading) {
    m_OnReading = reading; 
    } this.OnSucceed=function(succeed)
    {
    m_OnSucceed=succeed;
    } this.OnTimeout=function(timeout)
    {
    m_timer=window.setTimeout(timeout,10000);
    } this.invokeServer = function(send_data, method) {
        if (!m_xmlReq) return;
        var thisUrl = this.Url;
        if (this.Url.indexOf("?") > 0)
            thisUrl += "&r=" + (new Date()).getMilliseconds() + "&" + send_data.toString();
        else
            thisUrl += "?r=" + (new Date()).getMilliseconds() + "&" + send_data.toString();
        m_xmlReq.open(method, thisUrl, true);
        if (method == 'POST')
            m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
        m_xmlReq.onreadystatechange = function() {
            if (m_xmlReq.readyState == 1) {
                m_OnReading();
            }
            else if (m_xmlReq.readyState == 4 && m_xmlReq.status == 200) {
                var result = null;
                if (m_xmlReq.responseText != "") {
                   // result = m_xmlReq.responseText;
                    // document.write(m_xmlReq.responseText);
                   eval("result=" + m_xmlReq.responseText);
                }
                m_OnSucceed(result);
                if (m_timer != null) window.clearTimeout(m_timer);
            }
        }
        m_xmlReq.send('');
    }
    } 这是我的代码
      

  4.   

    m_xmlReq.responseText返回的内容是什么??
      

  5.   

    eval("alert('aaa')")相当于执行alert('aaa'),你的能执行吗?