Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery$.post发行_Jquery - Fatal编程技术网

Jquery$.post发行

Jquery$.post发行,jquery,Jquery,我有下面的代码,在浏览后读取文件名,并使用POST将其发送到另一个页面。如果我在$.post之后有警报,那么它可以正常工作。如果我删除了警报消息,则post不会将文件名转发到其他页面 <input type="file" name="fileupload" id="fileupload" value=""> //Jquery代码 $("#fileupload").change(function() { if ($("#fileupload").val().length

我有下面的代码,在浏览后读取文件名,并使用POST将其发送到另一个页面。如果我在$.post之后有警报,那么它可以正常工作。如果我删除了警报消息,则post不会将文件名转发到其他页面

<input type="file" name="fileupload" id="fileupload" value="">

//Jquery代码

$("#fileupload").change(function() {
    if ($("#fileupload").val().length > 0) {
        $.post("ReadExcel.jsp", {
            filename: $("#fileupload").val(),
            processId: < %= processId % >
        });
        alert($("#fileupload").val()); // **If I remove this alert, then the code doesn't works** 
    }
    location.reload();
});​
$(“#文件上传”).change(函数(){
if($(“#fileupload”).val().length>0){
$.post(“ReadExcel.jsp”{
文件名:$(“#文件上载”).val(),
processId:<%=processId%>
});
警报($(“#fileupload”).val();//**如果我删除此警报,则代码不起作用**
}
location.reload();
});​

也许是这样的

  $("#fileupload").change(function() {
        if ($("#fileupload").val().length > 0) {
            $.post("ReadExcel.jsp", {
                data: {
                   'variable-name' : $("#fileupload").val()
                },
                processId: < %= processId % >
            });
            alert($("#fileupload").val()); // **If I remove this alert, then the code doesn't works** 
        }
        location.reload();
    });​
$(“#文件上传”).change(函数(){
if($(“#fileupload”).val().length>0){
$.post(“ReadExcel.jsp”{
数据:{
'变量名':$(“#文件上载”).val()
},
processId:<%=processId%>
});
警报($(“#fileupload”).val();//**如果我删除此警报,则代码不起作用**
}
location.reload();
});​

我很难用jQuery发布文件数据,所以我制作了一个表单,并添加了一个I框架,使用了很好的旧表单方法。我不确定你到底想达到什么目的,(发布文件数据,或者只是文件名),但无论如何这里有一些提示

我敢打赌,当你发出警告时,脚本会在你点击OK时暂停,这样就有时间从帖子中得到他的回复。当您取下脚本时,脚本将在客户端收到其答案之前继续执行

修改代码,使下一个操作在回调中,(将在获得响应后运行);$。post(文件名、值、回调)

此代码应适用于:

<input type="file" name="fileupload" id="fileupload" value="">
// Jquery code
   $("#fileupload").change(function() {
   if($("#fileupload").val().length > 0) {    

       $.post("ReadExcel.jsp", {
            filename: $("#fileupload").val(), 
            processId: <%=processId%>
       },function(data){
             location.reload();          //THIS IS THE CALLBACK 
       });

 alert($("#fileupload").val());  // **If I remove this alert, then the code doesn't works**     
     }    
});
如果出现问题,您将能够通知用户


jQuery post是一件了不起的事情,回调也是一个很棒的工具。享受吧

好吧,这还不清楚:为什么
location.reload()
不在
$的成功回调函数(第三个可能的参数)中。post
?你说的是“另一页”?我看不到涉及到另一个页面?+1作为解释(您可以格式化代码):如果您在post操作完成之前重新加载页面,那么糟糕的回调将无法返回。。。它消失在海里了!谢谢你,路易斯。你的回答起了作用,解决了问题。非常感谢。
if(data ==1) location.reload();
else alert("something went wrong");