gpt4 book ai didi

c# - jQuery 不加载响应

转载 作者:行者123 更新时间:2023-11-29 18:35:37 25 4
gpt4 key购买 nike

我通常使用 ASP.NET MVC 2,但它存在一些问题,所以我开始使用 ASP.NET MVC 2 + jQuery,一切正常。但是有一个问题,jQuery 不加载我的响应。在 ASP.NET MVC 端,我重新渲染了一个局部 View ,我也在客户端获得了响应,但没有呈现任何内容。我该如何解决这个问题?

这是 jquery 代码:

function addCredential(state, id) {
var daten = getJson(state, id);
$.ajax(
{
type: "POST",
url: "/Account/SetCredential/",
data: daten,
dataType: "json",
success: function(partialView) {
$('#Credentials').replaceWith(partialView);
location.reload();
}
});
return true;
};

function getJson(state,id) {
var username = $('#username').val();
return {"username": username, "credential_id": id , "state": state };
};

最佳答案

问题看起来像 location.reload();

这就是在您使用 AJAX 更新页面后重新加载页面,有效地将其状态返回到您使用 .replaceWith() 插入内容之前的状态 p>

更新:看起来您正在使用 dataType: "json" 并将其插入到 DOM 中?这可能也是一个问题。如果 View 以 HTML 格式返回,则应将其替换为 dataType: "html"

关于c# - jQuery 不加载响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3574876/

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