Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:10:40+00:00 2026-06-13T09:10:40+00:00

I have below code that reads file name after browse and sends it to

  • 0

I have below code that reads file name after browse and sends it to another page using POST. if i have alert after $.post, then it works fine. If I remove the alert message, then post is not forwarding the file name to another page.

<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 % >
        });
        alert($("#fileupload").val()); // **If I remove this alert, then the code doesn't works** 
    }
    location.reload();
});​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:10:42+00:00Added an answer on June 13, 2026 at 9:10 am

    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.

    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.

    Modify your code so your next action is in the callback, (will run after getting the response); $.post(filename, value, callback);

    This code should work:

    <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**     
         }    
    });
    

    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.

    So by changing the call back with

    if(data ==1) location.reload();
    else alert("something went wrong");
    

    You will be able to notify the user is something goes wrong.

    jQuery post is an amazing thing, callback is great tools too..enjoy

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have the following code that reads a text file line by line.
I have code that looks more or less like the code below but it
I have the code below that hides and shows the navigational bar. It is
I have this javascript code below that uses jquery, it is suppoed to be
below i have a code that runs in most of my simple programs ..
I have a piece of code (below) that can get the text of an
Background: I have a WPF UserControl (MainControl - not shown in code below) that
I have the code below on form so that the user submits the form
I have the code below. I'm wondering that does the self.value and _value have
I have a plot (sample code pasted below) that I am trying to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.