Firefox 未传输 Ajax.Updater POST 参数

发布于 2025-01-08 02:43:41 字数 2965 浏览 0 评论 0原文

我正在调试别人编写的代码 - 我也是 Ajax 和 JS 的新手。下面显示的代码使用 Ajax(Prototype JavaScript 框架,版本 1.6.0.1)提交简单的联系表单并使用响应更新页面。它在 IE8 上完美运行,但在 Firefox 上失败。我已将故障追溯到 post 参数。当 Firefox 作为浏览器时,目标文件 mail.php 不会接收任何 POST 参数。不仅缺少值 - 帖子中未定义参数。该网址有效。表单、Ajax JS 文件和 mail.php 脚本都位于同一域中。

我尝试过定义 var 参数的变体,如其他几个 Stack Overflow 帖子中所示(内联、不同的赋值方法等)。所有结果都与下面的代码相同。

有什么线索吗?

FF results
Please try again. responseText='', url='http://domain.com/builder/mail.php', 
form_name='dom', form_message='testing', form_email='[email protected]', 
form_to='[email protected]'

IE8 results
Message Sent!

JS function
function sendForm(F)
{
    $("contact_form").hide();
    $("ajax-loader").show();

    var url = site_url+'mail.php';

    var form_message = escape($("message").value);
    var form_name = escape($("name").value);
    var form_address = escape($("address").value);
    var form_phone = escape($("phone").value);
    var form_email = escape($("email").value);
    var form_how_learn = escape($("how_learn").value);
    var form_to = escape($("to").value);

    var params = {message: form_message, 
                name: form_name, 
                address: form_address, 
                phone: form_phone, 
                email: form_email, 
                how_learn: form_how_learn,
                to: form_to};

    var ajax = new Ajax.Updater(
        'contact_form',
        url, 
        {
            method: 'post',
            parameters: params,
            onComplete: function (response) 
            {
                $("ajax-loader").hide();
                if (response.responseText == "ok")
                {
                    $("contact_form").innerHTML = "<p style=\"color:green;\">Message Sent!</p>";
                    $("contact_form").show();
                }
                else
                {
                    // Debug code added
                    $("contact_form").innerHTML = "<p style=\"color:red;\">Please try again."+
                        " responseText='"+response.responseText+"',"+
                        " url='"+url+"',"+
                        " form_name='"+form_name+"',"+
                        " form_message='"+form_message+"',"+
                        " form_email='"+form_email+"',"+
                        " form_to='"+form_to+"'"+
                        "</p>";
                    $("contact_form").show();
                }
            },
            onFailure: function ()
            {
                $("ajax-loader").hide();
                $("contact_form").innerHTML = "<p style=\"color:red;\">Please try again.</p>";
                $("contact_form").show();
            }
        }
    );
    return false;
}

I am debugging code written by someone else - I am also a newbie at Ajax and JS. The code shown below uses Ajax (Prototype JavaScript framework, version 1.6.0.1) to submit a simple contact form and update the page with the response. It works perfectly with IE8 and fails with Firefox. I have traced the failure to the post parameters. The target file, mail.php, is not receiving any POST parameters when Firefox is the browser. Not just the values are missing - the params are not defined in the post. The URL is valid. The form, the Ajax JS files and the mail.php script are all on the same domain.

I have tried variations on defining var params as shown in several other Stack Overflow posts (inline, different assignment methods, etc). All produced the same results as the code below.

Any clue what is wrong?

FF results
Please try again. responseText='', url='http://domain.com/builder/mail.php', 
form_name='dom', form_message='testing', form_email='[email protected]', 
form_to='[email protected]'

IE8 results
Message Sent!

JS function
function sendForm(F)
{
    $("contact_form").hide();
    $("ajax-loader").show();

    var url = site_url+'mail.php';

    var form_message = escape($("message").value);
    var form_name = escape($("name").value);
    var form_address = escape($("address").value);
    var form_phone = escape($("phone").value);
    var form_email = escape($("email").value);
    var form_how_learn = escape($("how_learn").value);
    var form_to = escape($("to").value);

    var params = {message: form_message, 
                name: form_name, 
                address: form_address, 
                phone: form_phone, 
                email: form_email, 
                how_learn: form_how_learn,
                to: form_to};

    var ajax = new Ajax.Updater(
        'contact_form',
        url, 
        {
            method: 'post',
            parameters: params,
            onComplete: function (response) 
            {
                $("ajax-loader").hide();
                if (response.responseText == "ok")
                {
                    $("contact_form").innerHTML = "<p style=\"color:green;\">Message Sent!</p>";
                    $("contact_form").show();
                }
                else
                {
                    // Debug code added
                    $("contact_form").innerHTML = "<p style=\"color:red;\">Please try again."+
                        " responseText='"+response.responseText+"',"+
                        " url='"+url+"',"+
                        " form_name='"+form_name+"',"+
                        " form_message='"+form_message+"',"+
                        " form_email='"+form_email+"',"+
                        " form_to='"+form_to+"'"+
                        "</p>";
                    $("contact_form").show();
                }
            },
            onFailure: function ()
            {
                $("ajax-loader").hide();
                $("contact_form").innerHTML = "<p style=\"color:red;\">Please try again.</p>";
                $("contact_form").show();
            }
        }
    );
    return false;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文