0

I've got a problem with this code. I want to send to the server a file and other variables which are only text.

Imageform is a DataFomr object.

This is my code at the moment:

name = "Peter";
$.ajax({
    url: "?c=produ&a=send_form",
    type: "POST",
    data: imageform"&name="name,
    processData : false,
    contentType: false,
});

But I recived on the server nothing.

How I can to send a file plus text. Thanks :)

Mario
  • 1,841
  • 4
  • 16
  • 23

1 Answers1

0

Let me know if this is possible, as your form processing will have to deal with the 'name value' structure of .serializeArray();

var formJson = $("#formId").serializeArray();
var nameJson = {"name":"name", "value":"Peter"};
formJson.push(nameJson);
$.ajax({
    url: "?c=produ&a=send_form",
    type: "POST",
    data: formJson ,
    processData : false,
    contentType: false,
});
DefyGravity
  • 5,681
  • 5
  • 32
  • 47
  • Why do you use this line: var nameJson = {"name":"name", "value":"Peter"}; I need to send the DataForm object in the AJAX. How I can do it? I have to test the code and I will answer you. Thank you so much :) – Mario Oct 19 '11 at 21:25
  • I just have tested the code and it doesn't work. No data is recieved in the url. – Mario Oct 19 '11 at 22:16
  • did you replace "#formId" with the actual html ID of the
    tag? did you confirm your back end form processing is ok with the altered structure of this return? Can you trap the xhr request posting to your server and post it?
    – DefyGravity Oct 20 '11 at 14:11
  • Yes, in "?c=produ&a=send_form" I only have a print_r of the arrays of $_POST and $_FILES and the don't returned nothing. – Mario Oct 20 '11 at 21:59
  • you can read [this](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery) question on stackoverflow. – Alper Oct 26 '11 at 14:32