我有兩個AJAX形式:Ajax.BeginForm總是excecuting一個「POST」
@using (Ajax.BeginForm("Index2","Home",
new AjaxOptions
{
UpdateTargetId = "result",
HttpMethod = "PUT"
},
new
{
onclick = "Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));",
onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'PUT', updateTargetId: 'result' });"
}))
{
<input type="hidden" name="id" value='1'/>
<input type="submit" value="OK Put" />
}
@using (Ajax.BeginForm("Index2","Home",
new AjaxOptions
{
UpdateTargetId = "result",
HttpMethod = "DELETE"
},
new
{
onclick = "Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));",
onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'DELETE', updateTargetId: 'result' });"
}))
{
<input type="hidden" name="id" value='1'/>
<input type="submit" value="Error Delete" />
}
在第一個,我excecuting一個PUT
,第二個一DELETE
,但在提琴手送花兒給人說,是POST
。
要繼續測試,我添加了一個代碼(這個代碼僅與測試的建議)
(function() {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (a) {
console.log("~>" + a);
//console.log(this);
var x = a;
this.addEventListener('load', function() {
//console.log(this);
if(x == "POST"){
alert("Was a POST");
}
});
origOpen.apply(this, arguments);
};
})();
爲什麼我的其他HttpVerbs總是被excecuted爲POST
?
@PatrickHofman基本上,這是不同的,因爲這個問題它是基於線程的解決方案,並與'MVC'符號相關型號,問題不是以'jquery'的,它與'Razor' – MrMins 2015-02-24 14:35:41