See:
HTML
<form id="form" enctype="multipart/form-data" action="paginax.php" method="post">
<input name="nome_arquivo" type="file"/>
<input type="hidden" value="valor_name1" name="name1"/>
<input type="hidden" value="valor_name" name="name2"/>
</form>
JAVASCRIPT
$(document).ready(function(){
$("#enviar_form").click(function(){
$.ajax({
method:"POST",
data: $("#form").serialize(),
url: "paginax.php",
contentType:"multipart/form-data; boundary=---------------------------1922310697355",
headers:{
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate",
"Accept-Language":"pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
"Content-Length":"781659",
"Content-Type":"multipart/form-data; boundary=---------------------------1922310697355",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0"
},
success:function(){alert("foi!");},
error: function(e){alert(e);}
});
});
});
The question is, I set up the headers in ajax, and in the Content-type of the header I put: multipart/form-data; boundary=---------------------------1922310697355
.
My expectation was that the data to be sent would be divided by what I determined in the boundary ( -------------------------- -1922310697355 ).
However, when I query the request that is made, I see it being put like this:
name1=valor_name1&name2=valor_name
That is, in addition to not being split as I determined in boundary, the image I selected on the form (in the input [type = file]) does not seem to be sent as well.
I have 3 questions to address:
1st Why is not POST sent as I have determined in the division?
2 because the image is not sent, since I can not see it in the data sent in the POST (unless it is available visually only by the $ _FILES magic var).
3 °
if I determine in headers:
of $.jquery
Content-type:...
, do I need to set the Content:Type:
field of my%