$(".btnSavePurpose").click(function(e){
e.preventDefault();
var item=$(this);
$.post("url",
item.closest("form").serialize(), function(data){
if(data.Status=="Success")
{
//Let's replace the form with messsage
alert("Updated Successfully");
}
else
{
alert(data.ErrorMessage);
}
});
});
我想用ajax發表我的表單。我用$ post()jquery函數。我正在獲取沒有上傳文件的所有數據。我添加了enctype來形成。我得到Request.File [「文件」]爲空。我怎麼能retrive上傳文件
<form method="post" id="profile-form" enctype="multipart/form-data">
<table>
<tr>
<td style="width: 25%">
Profile Name<span class="Require"> *</span>
</td>
<td style="width: 10%">
:
</td>
<td style="width: 70%">@Html.TextBoxFor(m => m.ProfileName, new { @class = "formTextBox" })
</td>
</tr>
<tr>
<td>
My Ocupation<span class="Require"> *</span>
</td>
<td>
:
</td>
<td>@Html.TextBoxFor(m => m.Ocupation, new { @class = "formTextBox" })
</td>
</tr>
<tr>
<td>
Upload New Profile Photo
</td>
<td>
:
</td>
<td>
<input type="file" name="file" id="file" runat="server" accept="gif|jpg|png|jpeg|bmp" />
</td>
</tr>
</table>
<input type="submit" id="btnSubmit" value="Submit" class="formButton" />
</form>
http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload –