gpt4 book ai didi

jquery - 同步XMLHttpRequest..asp.net mvc

转载 作者:行者123 更新时间:2023-12-01 04:05:47 25 4
gpt4 key购买 nike

我有这个 Controller :

public ActionResult Index()
{

return View();
}

[HttpGet]
public PartialViewResult Code()
{
return PartialView("Code");
}

[HttpPost]
public PartialViewResult Code(string code)
{

return PartialView("Code");
}

我的索引 View 中有部分调用

@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/.

我用谷歌搜索但找不到可以根据我的问题定制的答案..

最佳答案

如果没有明确给出任何操作,任何表单(AJAX 或其他形式)都将默认为当前页面的 URL。您可以使用an overload of the BeginForm method指定操作:

Ajax.BeginForm("Code", new AjaxOptions { ... })
<小时/>

关于同步 AJAX 的警告,这只是告诉您该行为已被弃用。在某个地方(我不确定在哪里)您告诉 AJAX 操作要同步调用。 AJAX 中的“A”代表“异步”。浏览器只是告诉您 AJAX 应该是异步的。应该是这样。

无论代码指示 AJAX 调用是同步的(我在这里没有看到任何这样做的东西,所以它可能在其他地方)都应该更改。

关于jquery - 同步XMLHttpRequest..asp.net mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28787554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com