0

here is an example of a simple ajax submit form:

$('#submit').click(function () {
    var myName = $('#name').val();
    var myContent = $('#content').val();

    // ajax
    $.ajax({
        type: 'post',
        url: '/ajax.process.php',
        data: {
            post_name: myName,
            post_content: myContent
        },
        dataType: 'json',
        success: function (data) {
            if (data.status.OK == 'OK') {
                console.log('OK');
                return false;
            } else {
                console.log('ERROR');
                return false;
            }
        }
    }); // end ajax
});

And this is my html:

   <form method='post' enctype='multipart/form-data' action='ajax.process.php' id='form-main'>
     <textarea cols='50' rows='5' id='content' name='post_content'></textarea>
         <input type='text' id='name' class=' name='post_name'>
         <input type='file' id='attach' name='attach'/>
          <input type='button' value='Submit' id='express-form-submit'>
   </form>

Just wondering why all the form works perfectly except for the attach, my server side script never catch a $_FILES.

Any ideas?

greenbandit
  • 2,267
  • 5
  • 30
  • 44

1 Answers1

1

the files cant be posted by jquery since you cant access their content. also, you don't post the form, you do a separate ajax request using jquery.

DoXicK
  • 4,784
  • 24
  • 22