3

Possible Duplicate:
How can I upload files asynchronously with jQuery?

How to use ajax post a upload file sametime I need to post a string check = 1?
data: fd + '&check=' + 1, this is not work. any suggestion?

Thanks.

var uf =$('.formname');
var fd = new FormData(formname);    
$.ajax({
    type: "POST",
    url: 'http://example.com/script.php',
    data: fd,
    processData: false,
    contentType: false,
    success: function(data){
    }
});

php

if($_FILES && $_POST['check'] == 1)
Community
  • 1
  • 1
user1775888
  • 3,147
  • 13
  • 45
  • 65

2 Answers2

1

You can use FormData.append to add a new set of values

var uf =$('.formname');
var fd = new FormData(uf[0]);
fd.append('check','1'); 
$.ajax({
    type: "POST",
    url: 'http://example.com/script.php',
    data: fd,
    processData: false,
    contentType: false,
    success: function(data){
    }
});
Musa
  • 96,336
  • 17
  • 118
  • 137
0

it's really complicated to pass a file through an ajax postback function. but try this it will help. this question has been asked before. Click and see the answers to the question

this library will help you achieve all that with alot of ease.

Mails Up will help. click this

Community
  • 1
  • 1