Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a hard time posting file data with jQuery so I made a form and added it with an i frame and use the good old form methods. I'm not sure what you exactly trying to achieve, (post the file data, or just the filename) but anyhow here some tips.</p> <p>My bet would be that when you put the alert, the script pause the time you click on OK so it has time to actually get his response from the post. As you take it off, the script continue executing before the client receive his answer.</p> <p>Modify your code so your next action is in the callback, (will run after getting the response); $.post(filename, value, callback);</p> <p>This code should work:</p> <pre><code>&lt;input type="file" name="fileupload" id="fileupload" value=""&gt; // Jquery code $("#fileupload").change(function() { if($("#fileupload").val().length &gt; 0) { $.post("ReadExcel.jsp", { filename: $("#fileupload").val(), processId: &lt;%=processId%&gt; },function(data){ location.reload(); //THIS IS THE CALLBACK }); alert($("#fileupload").val()); // **If I remove this alert, then the code doesn't works** } }); </code></pre> <p>Notice the function(data){} in the 3rd argument. data represent the returned value, so you can use it to verify if you script ran properly. You simply have to return a value, can be anything, i use 0 and 1 as in true or false.</p> <p>So by changing the call back with </p> <pre><code>if(data ==1) location.reload(); else alert("something went wrong"); </code></pre> <p>You will be able to notify the user is something goes wrong.</p> <p>jQuery post is an amazing thing, callback is great tools too..enjoy</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload