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

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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵