web front-end image upload

var formData = new FormData (); // Create an empty object here first
formData.append ( "file", document.getElementById ( "file") files [0].); // this is a picture of the input block, id for the file. appen first parameter is a field transmitted background
formData.append ( "reward_name", reward_name);
formData.append ( "reward_id", reward_id);
formData.append ( "reward_num", reward_num);
formData.append ( "exchange_num", exchange_num);
$ .ajax ({
url: "__ __ ROOT / index.php / Administration / Gamemanage / add_icon",
of the type: "POST",
processData: false, // note here, be sure to write false, because pictures, there is no need serialized
contentType: false, // point to note here is also a write to false.
Data: formData,
dataType: 'JSON',
Success: function (Data) {
IF (== data.info "Added successfully"


}else{
alert(data.info);
}
}
});

Guess you like

Origin www.cnblogs.com/PoisonousMushrooms/p/12559983.html