4
I need to send data from a form via ajax to the server (php). I used the Formdata() object but to no avail. Part of my jquery:
var formdata = new FormData($("#myform"));
var link = "form/insert";
$.ajax({
type: 'POST',
url: link,
data: formdata ,
processData: false,
contentType: false
}).done(function (data) {
$("div.container-fluid").html(data);
});
my html has:
<input type="text" class="form-control" id="name" placeholder="name" name="name">
<input type="file" id="arquivo" name="arquivo" />
Running the script only returns null. It would be possible to send the input text and the file via ajax?
Your link is with the correct url?
– David Schrammel
Yes! In my application I rewrite the link. I receive the data perfectly in php (the problem is the file upload)
– Bruno Nascimento
@I’m dev c# but I’ll try to help you hehehe', in c# I do it like this. Look at this javascript
– Brunno
@Brunno your code is ok. I tested it here and everything right. Since I still can’t upload the form along with the file. I’m playing the file upload to Callback. But, I didn’t want to do it this way. I would have some hint?
– Bruno Nascimento
@Brunonascimento try to do the following form If it works out, let me know and I’ll respond :)
– Brunno