jQuery$.post可以在chrome、safari中工作,但不能在FF中工作(声明成功回调函数未定义)

jQuery $.post works in chrome, safari, but not FF (claims success callback function is undefined)

本文关键字:工作 声明 FF 成功 回调 未定义 函数 但不能 chrome post safari      更新时间:2023-09-26

我有以下jQuery 1.7.2代码:

var theParams = encodeURIComponent(s1)+encodeURIComponent(s2);
$.post('/myURL',theParams,processData).error(errorResponse);
function processData(data,textStatus){
    blah blah;
}// end processData
function errorResponse() {
    blah blah;
}

此代码适用于Safari 6(Mac)、Chrome 21(Mac),Safari(iPad)、Chrome(iPad),但是FF 14(Mac)给了我以下错误:

ReferenceError: processData is not defined

奇怪的是,类似的代码(来自不同的页面)在FF:上运行得很好

var formData = $(form).serialize();
$.post('/myURL',formData,processData).error(errorResponse);
function processData(data,textStatus) {
    blah blah;
}// end processData
function errorResponse() {
    blah blah;
}

我试过重命名这个函数,但这导致了同样的未定义错误。我应该寻找什么来调试它?

尝试重新排列代码

var processData, errorResponse, theParams;
processData = function (data,textStatus){
    //blah blah;
};
errorResponse = function () {
    //blah blah;
};
theParams = encodeURIComponent(s1)+encodeURIComponent(s2);
$.post('/myURL',theParams,processData).error(errorResponse);

这对你有用吗?

你也能提供encodeURIComponent功能吗?

尝试在第1行之后添加此行:

theParams = encodeURIComponent(theParams);

我假设您的encodeURIComponent函数就是这个。