Ajax.request会引发语法错误,但会返回正确的值

时间:2022-10-07 15:25:01

I have a bunch of Ajax requests that execute just fine, but I end up with a syntax error in my browser.

我有一堆执行得很好的Ajax请求,但最终我的浏览器出现语法错误。

Can anyone see what's wrong with my request below?

任何人都可以在下面看到我的请求有什么问题吗?

function getName(refId)
{
    var resp = '';
    new Ajax.Request('/servlet/GetName',
    {
        method:'post',
        parameters: {'requestType':'ref',
                 'value':refId},
        onSuccess:function(transport)
        {
            setName((String(transport.responseText)).trim());
        }
    });
}

edit: This also seems to only throw the error the first time it gets called. If I clear the console, I don't continue to get errors.

编辑:这似乎只是在第一次调用时抛出错误。如果我清除控制台,我不会继续出错。

2 个解决方案

#1


I've gotten syntax errors using xmlhttprequest in Firefox to query non-xml as well. Firefox tries to parse the response as xml, and logs the error, but keeps working anyways.

我在Firefox中使用xmlhttprequest来查询non-xml时出现语法错误。 Firefox尝试将响应解析为xml,并记录错误,但仍然继续工作。

In my case, I added this to the php on the server side:
header('Content-Type: text/plain');

在我的例子中,我将它添加到服务器端的php:header('Content-Type:text / plain');

Someone reported a client-side fix here:
jQuery .getJSON Firefox 3 Syntax Error Undefined

有人在此报告了客户端修复:jQuery .getJSON Firefox 3语法错误未定义

#2


There is no root-property in the window object, according to W3Schools. Maybe if you use

根据W3Schools的说法,窗口对象中没有root属性。也许如果你使用

new Ajax.Request(document.domain + '/servlet/GetName', ...

it will work better.

它会更好地工作。

Edit, ah - I should learn to read. It does work, but throws a syntax error. Syntax errors != no implemented property... Sorry! But I will let my post stay anyway. ;)

编辑啊 - 我应该学会阅读。它确实有效,但会引发语法错误。语法错误!=没有实现属性...对不起!但无论如何我会留下我的帖子。 ;)

#1


I've gotten syntax errors using xmlhttprequest in Firefox to query non-xml as well. Firefox tries to parse the response as xml, and logs the error, but keeps working anyways.

我在Firefox中使用xmlhttprequest来查询non-xml时出现语法错误。 Firefox尝试将响应解析为xml,并记录错误,但仍然继续工作。

In my case, I added this to the php on the server side:
header('Content-Type: text/plain');

在我的例子中,我将它添加到服务器端的php:header('Content-Type:text / plain');

Someone reported a client-side fix here:
jQuery .getJSON Firefox 3 Syntax Error Undefined

有人在此报告了客户端修复:jQuery .getJSON Firefox 3语法错误未定义

#2


There is no root-property in the window object, according to W3Schools. Maybe if you use

根据W3Schools的说法,窗口对象中没有root属性。也许如果你使用

new Ajax.Request(document.domain + '/servlet/GetName', ...

it will work better.

它会更好地工作。

Edit, ah - I should learn to read. It does work, but throws a syntax error. Syntax errors != no implemented property... Sorry! But I will let my post stay anyway. ;)

编辑啊 - 我应该学会阅读。它确实有效,但会引发语法错误。语法错误!=没有实现属性...对不起!但无论如何我会留下我的帖子。 ;)