javascript - Ajax send image within data -


I am trying to send some data to Ajax and this data may contain an image.

I there is no form , so I can not present in a traditional way.

This is my html:

  & lt; Input type = "file" accept = "image / png, image / jpg, image / jpeg, image / bmp" id = "addProduct_image" & gt;   

Whenever the user changes the file, I get that value.

  var files; $ (Document) .on ('change', '#addProduct_image', function (e) {readyUpload (e);}); Upload the function ready (events) {files = event.target.files; }   

When I press the OK button I call an Ajax function.

  $ (document) .on ('click', '#addProduct_OK', function (e) {var img = new form data ($); $ .ee (files, functions (key, value) } {Img.append (key, value);}); $ .ajax ({url: 'responses / product val (), description: $ ("# addProduct_description"). Val (), image: img, status: php $ ("# AddProduct_status"). Val ()}, success: function (data) {console.log (data) );}});});   

I am currently getting the error on Chrome console

Unkit Type Error: Invalid Orientation

Ajax In-line How far am I far away from Ajax by sending an image with other data?

You need to send form data as data for Ajax request, so add additional parameters Should also be added to fomdata

  $ (document) .on ('click', '#addProduct_OK', function (e) {var img = new form data (); $ .EEC (Files, functions (key, values) {img.append (key, value);}); img.append ('title', $ ("# ('' condition '', $ (" # addProduct_status "). Val () ); $ .ajax ({url: 'responses / product.fip; type = product avatar', type: 'po (Data);}}};});    

Comments

Popular posts from this blog

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -