duanshan1511 2013-07-13 13:09
浏览 221
已采纳

jQuery $ .get请求无效

I have a file upload form, the following javascript fires as soon as the form is submitted:

$("#uploader").submit(function() {
    $("#indicator").show();
    alert("Submitted");
    var refresh = setInterval(function() {
        $.get("progress.php?getprogress&randval=" + Math.random(), function(data) {
            alert("Got " + data);
            $("#indicator .bar div").width(data + "%");
            if (data == 100) {
                clearTimeout(refresh);
                $("#indicator").addClass("done");
            }
        });
    }, 250);
});

I added some alerts to debug, I get the alert("Submitted"), but not the one alerting the data. The php is fine, opening it in a separate window gives the correct values, but the javascript does not get it. Another weird thing is that if I stop the page load, the alert() with the value fires and code is processed.

  • 写回答

3条回答 默认 最新

  • dongwei4444 2013-07-13 13:24
    关注

    Ok solved this by using an <iframe>:

    <form action="save.php" method="post" target="theiframe">...</form>
    <iframe name="theiframe" src="about:blank"></iframe>
    

    Still using javascript, but no e.preventDefault();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?