1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| {
function postAjax(url, data, success) {
var params = typeof data == 'string' ? data : Object.keys(data).map(
function(k){ return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) }
).join('&');
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.onreadystatechange = function() {
if (xhr.readyState>3 && xhr.status==200) { success(xhr.responseText); }
};
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('Content-Type', 'multipart/form-data', );
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader('Content-Disposition', 'attachment; Image_Legume="' + fileDialogImgLegume.fileUrl + '"');
xhr.send(params);
return xhr;
}
postAjax('http://localhost/legumes.php?action=update_legumes&Num_Legume=32',
{ //Nom_legume: ajouterNomLegume.text,
Image_legume: fileDialogImgLegume.fileUrl
},
function(data){ console.log(data); });
} |