How to see the Files uploaded in a form with ajax?

前端 未结 3 1612
萌比男神i
萌比男神i 2021-01-22 20:29

I\'m trying to upload a file send in a form. I\'m trying it with php, but between html and php I use JS and Jquery and ajax (because I don\'t want the page to reload). And I\'m

相关标签:
3条回答
  • 2021-01-22 21:07

    The $_POST variable on the page you are posting to is populated from the data you are submitting in the $.ajax call. That data has no file inputs, and I'm not sure it can. Take a look around for some handy plugins.

    This recommends using the jQuery Form Plugin: jQuery AJAX post with fileupload

    I've personally used Uploadify previously: http://www.uploadify.com/

    Or manually do it: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/

    0 讨论(0)
  • 2021-01-22 21:09

    Check if $_POST is also empty. $_POST and $_FILES tend to be empty when the file uploaded exceeds upload_max_filesize or post_max_size

    0 讨论(0)
  • 2021-01-22 21:11

    You can't do it with pure Ajax/jQuery, but you can do it in combination with the JavaScript FormData object which is supported in all latest versions of the major browsers.

    A really simple jQuery example can be found here: https://coderwall.com/p/p-n7eq

    A more detailed, yet pure JavaScript, can be found here: https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects?redirectlocale=en-US&redirectslug=Web%2FAPI%2FFormData%2FUsing_FormData_Objects

    0 讨论(0)
提交回复
热议问题