简体   繁体   中英

Image Upload JQuery form and PHP stop jumping page

I am working on an Image upload page. The upload works, but whenever i clicked the submit, it will go to the php page. I have returned false and set preventDefaut. Is there a way to stop it from going to php page?

my html code

 <form action="imageupload.php" method="post" id="image_form"enctype="multipart/form-data">
     <input id="update_image" name="file" type="file" maxlength="40">
     <input id ="image_submit" type="submit" name="submit" value="Submit">
 </form>
<div id="output"> </div>

my js code

var options = { 
        target:   "#output",   // target element(s) to be updated with server response 
       // beforeSubmit:  beforeSubmit,  // pre-submit callback 
        resetForm: true        // reset the form after successful submit 
    }; 

 $("#image_form").submit(function(e) { 
        $(this).ajaxSubmit(options);  //Ajax Submit form            
        // return false to prevent standard browser submit and page navigation
        e.preventDefault();
        return false; 
    }); 

try this

<form action="javascript: your function name" method="post" id="image_form" enctype="multipart/form-data">

or try to replace preventDefault

 $("#image_form").submit(function(event) { 
       event.preventDefault();
       $(this).ajaxSubmit(options);  //Ajax Submit form                               
       return false; 
       }); 

you can submit that without reload the page through the FromData object and an ajax call. That will make you available to submit a image or a file without reload the page, so you can forget the html form tag if you want plus the submit prevent default.

I've got an example in my blog:

http://sergiofraile.azurewebsites.net/?p=621

Sorry cus it's in spanish, but the code can be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM