我試圖使用jQuery JavaScript中執行我的控制器......是執行我的jquery代碼..問題中使用JSON jQuery和MVC
<script type="text/javascript">
$('form').submit(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: $(this).attr("action"),
data: $(this).serialize(),
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function(msg) {
var obj = msg.deserialize();
alert(msg);
}
});
});
</script>
現在它確實執行我的動作..
這裏是我的控制器類是執行樣本..
[AcceptVerbs(HttpVerbs.Post)]
[Url("Account/LogOn")]
public virtual ActionResult LogOn(string Username, string Password)
{
if (Username == "test")
{
return Json(new { Success = true });
}
else
{
return Json(new { Success = false });
}
}
問題是...當我運行的方法..它只是嘗試下載一個包含結果的「登錄」文件..我如何把它放回到jquery中的對象,所以我可以正確處理它,我嘗試添加成功標記並嘗試檢查味精,但它甚至不運行它
嘗試添加功能爲「錯誤」或「完整」的回調而不是「成功」,這樣就可以看到正在發生的實際的錯誤,如果有的話。 – 2010-06-09 14:31:52
'msg.deserialize()'對我來說看起來像一個隱藏的功能。 – jAndy 2010-06-09 14:33:04
你的意思是提示你下載一個「文件」,如果你保存它,然後看看內容,該文件有正確的JSON?問題在於你的javascripts提示用戶下載JSON而不是在幕後處理它? – Nate 2010-06-09 14:35:16