<form class="upload-box"> <input type="file" id="file" name="file1" /> <span id="upload-error" class="error" /> <input type="submit" id="upload-button" value="upload" /></form>
$(document).on("#upload-button", "click", function() { $.ajax({ type: "POST", url: "/Upload", async: true, data: $(".upload-box").serialize(), contentType: "multipart/form-data", processData: false, success: function(msg) { alert("File has been uploaded successfully"); }, error:function(msg) { $("#upload-error").html("Couldn't upload file"); } });});
温温酱
慕莱坞森