对于ajax上传,您需要使用方法中
xmlHttpRequest已经可用的
jQuery.ajax(),但要使用
FormData。
如果您的目标不是IE旧版(例如7,8),则可以使用
FormData。必须注意的一件事是您必须设置
contentType,processData为
false。
请参阅以下示例:
var name = $('#name').val();var somethingElse = $('#somethingElse').val();var fd = new FormData();var dataArr = { name: name, somethingElse: somethingElse, file : fd.append('file', $('#fileUpload').get(0).files[0]) // put the file here};MYELEMENT.click(function(e) { e.preventDefault(); $.ajax({ url: "PATH/logic/logic_update_client_allg.php", type: "POST", data: dataArr, //<----post here the files and other values processdata: false, // tell jQuery not to process the data contentType: false // tell jQuery not to set contentType success: function(dataArr) { // works }, error: function() { // doesnt work } });});


