使用eval()预期id,string或integer

时间:2011-04-29 10:26:40

标签: javascript

我在IE中遇到一个奇怪的错误..但FF和chrome都没有问题

当我提醒变量时,我得到了这个:

json_post('delete_accounting', 'json.action.php?action=delete_accounting', 'id=682', 'rtn_accounting', {tr_id:'tr_acc682', enc_id:374, delete:1});

但是当我想要eval()时,我得到了这个错误(错误是从丹麦语中翻译出来的,所以我不知道它是如何用英语写的?)

id, string or integer was expected

编辑:

var xmlhttp = {};
function json_post(request_var, response, get_str, callback_function, callback_var)
{
    request_var += Math.floor(Math.random()*999).toString();

    CNSTR.mouseLoader.cnstr();

    if(window.XMLHttpRequest) xmlhttp[request_var] = new XMLHttpRequest();
    else if(window.ActiveXObject) xmlhttp[request_var] = new ActiveXObject('Microsoft.XMLHTTP');

    xmlhttp[request_var].open('POST', response, true);
    xmlhttp[request_var].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp[request_var].onreadystatechange = function()
    {
        if(xmlhttp[request_var].readyState == 4)
        {
            CNSTR.mouseLoader.dstr();

            if(callback_function) eval(callback_function+'('+xmlhttp[request_var].responseText+(callback_var ? ', callback_var':'')+')');
        }
    }
    xmlhttp[request_var].send(get_str);
}

我很确定错误发生在eval()中,因为当我将sting作为真实代码运行时没有问题。

像这样:

json_post('delete_accounting', 'json.action.php?action=delete_accounting', 'id=682', 'rtn_accounting', {tr_id:'tr_acc682', enc_id:374, delete:1});

我还尝试在回调函数rtn_accounting()中转义所有内容,并且在与eval()的同一行中仍然存在相同的错误

1 个答案:

答案 0 :(得分:0)

通过在最后一个参数中的对象中添加引号是可行的

json_post('delete_accounting', 'json.action.php?action=delete_accounting', 'id=682', 'rtn_accounting', {'tr_id':'tr_acc682', 'enc_id':374, 'delete':1});