![](/img/trans.png)
[英]Passing data from view to controller using Ajax in Laravel
[英]Passing data from View to Controller using Ajax results in 404 error on the controller method
我正在嘗試將數據從 View 傳遞到 Controller Action 方法。 使用 Ajax 將數據傳遞給控制器,但控制器不接收數據並且它始終為 null,從而導致 404 錯誤。 有人可以查看此內容並指出需要修復的內容嗎?
視圖中的 Ajax 調用 -
function openErrorDetails(errors) {
$.ajax({
type: 'POST',
url: "/Home/ErrorDetails",
dataType: 'json',
data: JSON.stringify({ errors }),
success: function (data) {
var win = window.open();
win.document.write(data);
}
});
}
使用錨標記 OnClick 事件調用 Ajax 函數以打開一個包含錯誤詳細信息的新窗口 -
var exception = "onClick='openErrorDetails(" + JSON.stringify(data) + ")'> 查看詳情";
控制器 -
[HttpPost]
public ActionResult ErrorDetails(string errors)
{
if (errors != null)
{
dynamic errorMessages = JsonConvert.DeserializeObject(errors);
return View("ErrorDetails", errorMessages);
}
else
{
return new HttpNotFoundResult();
}
}
這解決了它的數據:{錯誤:JSON.stringify({錯誤})},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.