1

我有以下 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;
}

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

4

2 回答 2

0

尝试重新排列您的代码

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功能吗?

于 2012-08-29T09:59:16.693 回答
0

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

theParams = encodeURIComponent(theParams);

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

于 2012-08-29T10:03:08.447 回答