title: Post Parameter and then Ajax Upload Image Separately
body: <p>My site is to post status and picture like facebook do.
  I would like to post the status and after that ajax upload the image separately, however it failed. Any solution for this?</p>
  
  <p>javascript</p>
  
  <pre><code>$('#postIdeaBtn').click( function() {
                      $("#postIdeaForm").submit();
                  });
  
                   $("#postIdeaForm").validate({
                   errorElement:"div",
                   rules: {
                   dateIdea: "required"
                   },
                   messages: {
                   dateIdea: ""
                   },
                   submitHandler: function() {
                   $.post("sites/all/themes/dating/ajaxpages/post-date-ideas.php", $("#postIdeaForm").serialize(), 
                   function(data) {
                       if(data == 'noImage') {
                           window.location.href='date_ideas';//refresh page
                       }
                       else if(data == 'haveImage') {
                          //upload image
  
                           new AjaxUpload('selector', {
                                  action: 'sites/all/themes/dating/ajaxpages/upload-wallpost-image.php',
                                  name: 'image',
                                  onSubmit: function(file, extension) {
                                      //ext not allowed
                                      if (! (ext &amp;&amp; /^(jpg|png|jpeg|gif)$/.test(ext))) {
                                      alert('Only JPG or PNG images are allowed');
                                      return false;
                                  }
                                  },
                                  onComplete: function(file, response) {
  
                                      $('#uploadImgPreview').attr("src","sites/default/files/"+response).show();
                                  }
                                });
  
  
                       } 
                      });
                  return false;
                   }
                  });
  </code></pre>