javascript - Image isn't posting while using e.preventDefault() in jquery ajax -


i got wired problem while posting form using jquery ajax. have multiple image upload field. while use e.preventdefault() function images aren't uploading. while disable code. remains fine. here code snippet markup, js , php

html

<form class="shoform" id="contact-entry" name="contact-entry" action="project-up-eng.php" method="post" enctype="multipart/form-data"> <input class="pic" id="img" type="file" multiple="multiple" name="imgfile[]" /> <input class="submitbtn" id="submitbtn" type="submit" value="add"></input> </form> 

js

$("#submitbtn").click(function(){           $("#contact-entry").submit(function() {         /* act on event */          e.preventdefault();         $.post('project-up-eng.php',$(this).serialize(), function()                         {                         alert("ok");                       });      });   }); 

php:

mkdir("projects/".$_post['name']); $path="projects/".$_post['name']; for($i=0;$i<count($_files['imgfile']['size']);$i++) { $file = $path."/".$_files['imgfile']['name'][$i]; move_uploaded_file($_files['imgfile']['tmp_name'][$i],$file);     } 

unfortunately, can not submit forms files on ajax classic html. when call e.preventdefault(), regular file upload not performed, , $.post call manually unable want.

you can upload javascript in new browsers new html 5 functionality. see "how can upload files ajax".


Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -