How to use ajax post upload file sametime I need to send the check = 1 string? `data: fd + '& check =' + 1,`?

Possible duplicate:
How can I upload files asynchronously using jQuery?

How to use ajax post upload file sametime I need to send the check = 1 string?
data: fd + '&check=' + 1,

This does not work. any suggestion?

Thank.

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)

      

+3


source to share


2 answers


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){
    }
});

      

+1


source


it's really tricky to pass the file through the 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 of this with great ease.



Helped by Mails Up. Press here

0


source







All Articles