0

I'm passing information in AJAX to "my.php" like this

HTML

<textarea name="Comment"></textarea> 
<input id="images" type="file" name="upload_attachment[]" multiple="multiple"  /> 
<input id="new_review" type="submit" value="Submit">

JS

jQuery('input[type=submit]').on('click', function () {
        
        jQuery.ajax({
            url: 'https://site/my.php',
            data: {
                post_id: 15 ,
                text: jQuery("textarea[name=Comment]").val(),
                images: jQuery("#images").val(),
            },
            success:function(data){
                window.location='https://site/my.url'
            }
        });
    });

The textarea passes well but my file input only passes a fakepath and the name of the file. How to correctly pass the file to "my.php" in a clean and simple way ?

Odjone
  • 35
  • 1
  • 7
  • use FormData please – Ken Lee Jan 25 '22 at 10:23
  • Or there's https://stackoverflow.com/questions/2320069/jquery-ajax-file-upload, or about 20 others. Have you done any research? – ADyson Jan 25 '22 at 10:23
  • @KenLee Thanks for the lead =) I appreciate – Odjone Jan 25 '22 at 10:30
  • No problem. In future please do a bit more basic research then you don't waste your effort creating a question which is a duplicate of an easily-google-able one :-) – ADyson Jan 25 '22 at 10:30
  • @ADyson That's true, I spent time but I'm not familiar with all the possibilities and some of them look very complicated. Not the one you redirect to. Thanks again ! – Odjone Jan 25 '22 at 10:31
  • Sure, but if you google the exact title of your question then the links I provided are the first results on the page... – ADyson Jan 25 '22 at 10:33
  • @ADyson true. do ! =) – Odjone Jan 25 '22 at 10:37

0 Answers0