gpt4 book ai didi

javascript - Ajax 请求 asp.net mvc Controller 返回 500 - 内部服务器错误

转载 作者:太空狗 更新时间:2023-10-30 01:01:49 25 4
gpt4 key购买 nike

我在 View 上有这两个 select:

<select class="input-sm form-control input-s-sm inline" onchange="carregarCidades()" id="comboEstado">
...
</select>

<select class="input-sm form-control input-s-sm inline" id="comboCidade">
...
</select>

第一个代表一个州,当我选择它时,我想执行 carregarCidades 函数来加载该统计的城市,然后将它们加载到另一个选择中。这是函数:

function carregarCidades() {
var url = "@Url.Action("CarregarCidades", "Usuario")";

var estado = $("#comboEstado").find(":selected").text();

$.get(url, { pEstado: estado }, function (cidades) {
$("#comboCidade").html(""); // clear before appending new list
$.each(cidade, function (i, cidade) {
$("#comboCidade").append(
$('<option></option>').val(cidade.id_cidade).html(cidade.cidade));
});
});
}

现在,这是 UsuarioController 中的 CarregarCidades 操作:

public ActionResult CarregarCidades(string pEstado)
{
string cCidades = oVFP.BuscaCidade(pEstado);

DataSet dsC = new DataSet();
dsC.ReadXml(new StringReader(cCidades));

JsonResult result = Json(dsC.Tables["curretorno"]);
return result;
}

我正在调试 Action ,显然一切正常:

enter image description here enter image description here

但是,在 Action 返回 Json 结果后,回调函数没有在 jquery 代码上调用,我在控制台中收到 500 内部服务器错误。

最佳答案

你必须 JsonAllowRequestbehavior AllowGet 的参数,默认为 DenyGet :

JsonResult result = Json(dsC.Tables["curretorno"],JsonRequestBehavior.AllowGet);

您可以阅读有关 Why it is needed on this post 的信息.

关于javascript - Ajax 请求 asp.net mvc Controller 返回 500 - 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36632615/

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