同步 XMLHttpRequest.. asp.net mvc
Synchronous XMLHttpReques.. asp.net mvc
我有这个控制器:
public ActionResult Index()
{
return View();
}
[HttpGet]
public PartialViewResult Code()
{
return PartialView("Code");
}
[HttpPost]
public PartialViewResult Code(string code)
{
return PartialView("Code");
}
我的索引视图中有调用部分
@Html.Partial("Code")
这是我的部分观点
@model Kubeti.Models.Codes
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod="POST", UpdateTargetId = "result", InsertionMode=InsertionMode.Replace }))
{
@Html.EditorFor(x => x.code)
@Html.ValidationMessageFor(x => x.code)
<input type="submit" value="OK" />
}
<div id="result" style="width: 500px; height:500px; border:1px solid red;">
</div>
我的布局中当然有 jquery 和 unobtrusive.js
@RenderBody()
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
但是当我点击提交时,它进入了我的索引操作(我正在调试)而不是我的 PartialViewResult 代码。怎么了?
在控制台中有这个警告:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
我 google 但是找不到可以针对我的问题定制的答案..
任何表单(AJAX 或其他)如果没有明确给出操作,将默认为当前页面的 URL。您可以使用 an overload of the BeginForm
method 指定操作:
Ajax.BeginForm("Code", new AjaxOptions { ... })
关于同步 AJAX 的警告,这只是告诉您该行为已被弃用。在某个地方(我不确定在哪里)你告诉 AJAX 操作被同步调用。 AJAX中的"A"代表"Asynchronous"。浏览器只是告诉你你的 AJAX 应该是异步的。应该是这样。
只要代码指示 AJAX 同步调用(我在这里没有看到任何正在这样做的东西,所以它可能在其他地方)都应该更改。
我有这个控制器:
public ActionResult Index()
{
return View();
}
[HttpGet]
public PartialViewResult Code()
{
return PartialView("Code");
}
[HttpPost]
public PartialViewResult Code(string code)
{
return PartialView("Code");
}
我的索引视图中有调用部分
@Html.Partial("Code")
这是我的部分观点
@model Kubeti.Models.Codes
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod="POST", UpdateTargetId = "result", InsertionMode=InsertionMode.Replace }))
{
@Html.EditorFor(x => x.code)
@Html.ValidationMessageFor(x => x.code)
<input type="submit" value="OK" />
}
<div id="result" style="width: 500px; height:500px; border:1px solid red;">
</div>
我的布局中当然有 jquery 和 unobtrusive.js
@RenderBody()
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
但是当我点击提交时,它进入了我的索引操作(我正在调试)而不是我的 PartialViewResult 代码。怎么了?
在控制台中有这个警告:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
我 google 但是找不到可以针对我的问题定制的答案..
任何表单(AJAX 或其他)如果没有明确给出操作,将默认为当前页面的 URL。您可以使用 an overload of the BeginForm
method 指定操作:
Ajax.BeginForm("Code", new AjaxOptions { ... })
关于同步 AJAX 的警告,这只是告诉您该行为已被弃用。在某个地方(我不确定在哪里)你告诉 AJAX 操作被同步调用。 AJAX中的"A"代表"Asynchronous"。浏览器只是告诉你你的 AJAX 应该是异步的。应该是这样。
只要代码指示 AJAX 同步调用(我在这里没有看到任何正在这样做的东西,所以它可能在其他地方)都应该更改。