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

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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器