3

これがスクリプトです。他のすべてのブラウザでは問題なく動作するので、キャッシュの問題だと思っていましたが、そうではありませんでした。私は何時間も頭を叩いていますが、何も機能していません。

$.ajaxSetup({
    cache: false
});

$("#send").live('click', function () {
    console.log("AAAAA");
    $("#loader").show();
    $form = $('#reservationForm');

    $inputs = $form.find('input[name^="entry"]'),
    serializedData = $('#reservationForm :input[name^="entry"]').serialize();

    console.log(serializedData);
    serializedData += "&pageNumber=0&backupCache=1&submit=Submit";

    // fire off the request to /form.php
    $.ajax({
        url: "https://docs.google.com/spreadsheet/formResponse?formkey=d",
        // url: "https://docs.google.com/spreadsheet/formResponse?formkey=d;ifq",
        type: "post",
        data: serializedData,
        // callback handler that will be called on success
        success: function (response, textStatus, jqXHR) {
            // log a message to the console
            console.log("Hooray, it worked!");
            $("#loader").hide();
            document.getElementById('error<?php echo"$uname";?>').innerHTML = error;
            $("#success").fadeIn();
            setTimeout(function () {
                $("#success").fadeOut();
            }, 5000);
        },
        // callback handler that will be called on error
        error: function (jqXHR, textStatus, errorThrown) {
            // log the error to the console
            console.log("The following error occured: " + textStatus, errorThrown);
            alert('Due to an unknown error, your form was not submitted, please resubmit it or try later.');
        },
        // callback handler that will be called on completion
        // which means, either on success or error
        complete: function () {
            // enable the inputs
            $inputs.removeAttr("disabled");
        }
    });

    // prevent default posting of form
    event.preventDefault();

});
4

3 に答える 3

2

console.log は、IE で開発者ツール (F12 で開く) を開いた後に利用できます。オンにしてみるか、代わりにコードでアラートを使用してください。またはtry catchを使用します。

try{
    console.log('worked')
}
catch(err){
}

また、イベント変数が未定義かどうかを確認したい場合があります。

event= event || window.event;
event.preventDefault();
于 2012-12-01T14:41:35.523 に答える
0

スクリプトの冒頭で、ハンドラーに「イベント」宣言を追加していません。

$("#send").live('click', function () {

次のようにする必要があります。

$("#send").live('click', function (e) {

スクリプトの最後には、変数 event への参照があります。

 // prevent default posting of form
event.preventDefault();

IEには、グローバルイベントオブジェクト(参照している)に「preventDefualt」機能がないと思います。この機能は、jQueryによって渡される「e」イベントオブジェクトに追加されます。とにかく、「イベントが定義されていません」という他のすべてのブラウザでも失敗するはずです。これも試してください:

 // prevent default posting of form
e.preventDefault();

追加の注意: jQuery チームは現在、「ライブ」イベント バインディング関数の使用を推奨していません。代わりに、同等の形式の「on」関数を使用する必要があります。

于 2012-12-01T15:03:24.850 に答える
0

IE は ajax の応答のコンテンツ タイプを認識しません。したがって、 dataType 値をリクエストに入れると、機能するはずです。例えば ​​-

dataType: ($.browser.msie) ? "text" : "xml"
于 2012-12-01T15:04:03.387 に答える