0

I know this has been asked many times previously and I have searched through many of the questions here on stack overflow as well as google. I am still having a small issue and I would love any help you guys can offer.

Basically I am trying to grab my image data and send it to my php script via jquery. Once it gets to my php server it will do the uploading and etc. But my question is how can I get the data sent to my php file so I can do my upload function.

    var title = $('.title').val();
    var imageName = new FormData($('.bugImage'));
    alert(imageName);
    $.post('classes/bug-class.php', { type: 'add', image: imageName, title: title})

I am not able to use any plugins so I am just looking for a very basic way to send the image data via jquery. Currently went I activate this jquery command I get the error:

 Uncaught TypeError: Illegal invocation
Bryce
  • 447
  • 2
  • 9
  • 24
  • Are you required to asynchronously upload images using jQuery? I mimic the functionality with a hidden `iframe` which avoids using plugins, etc. – camelCase Oct 14 '15 at 23:46
  • Are you really only wanting jquery? Sorry i only know the real way to do it :( – Jesse Oct 14 '15 at 23:47
  • @Jesse what is the "real" way of doing it? – Bryce Oct 14 '15 at 23:50
  • He probably means multipart posts, not jquery. The only method I'm aware of is to use an iframe, the plugins I have used go this route as well. – skrilled Oct 14 '15 at 23:51
  • @camelCase The issue with the i-frame is that the data is in a bigger form with multiple items (text fields) in it. So once I hit submit it sends the information to the db and I am trying to get the filepath also sent to the db – Bryce Oct 14 '15 at 23:51
  • xhr.responseType = 'blob'; – Jesse Oct 14 '15 at 23:51
  • Marking duplicate - any answers outside of iframe method will not work on all browsers. But these answers also explain xhr2 method which works on newer browsers. – skrilled Oct 14 '15 at 23:52
  • I would really go with https://blueimp.github.io/jQuery-File-Upload/basic-plus.html – Pedro Lobito Oct 14 '15 at 23:54
  • 1
    @user1626342 that's okay, it can have a lot of data, you just need to put the `target` of the form to the hidden `iframe`. I **highly** recommend the `iframe` route for compatibility purposes. – camelCase Oct 15 '15 at 00:02
  • 1
    [Here is a great solution](http://stackoverflow.com/questions/2909442/how-to-make-asynchronousajax-file-upload-using-iframe) if you choose to go the `iframe` route – camelCase Oct 15 '15 at 00:04
  • 1
    @camelCase Thanks, I just used the iframe system! – Bryce Oct 15 '15 at 00:57

0 Answers0