This is my jquery:
$('#nmUsuario').on("dblclick", '.clique', function () {
CarregaDados($(this).parent().find(".idusuario").text());
})
function CarregaDados(ajaxParameter) {
var str = "";
$.ajax({
url: '/CadastroAcesso/CarregaDadosPagina',
datatype: 'json',
contentType: 'application/json;charset=utf-8',
type: 'POST',
data: { _nivel: JSON.stringify(ajaxParameter) },
success: function (data) {
alert(1);
$('#txtNome').val(data.result_carrega_pagina.NM_Usuario);
},
error: function (error) {
alert(2);
}
})
}
And this is my controller
[HttpPost]
public JsonResult CarregaDadosPagina(int _nivel)
{
RupturaEntities db = new RupturaEntities();
var result_carrega_pagina = db.Usuario
.Where(n => n.IDUsuario == _nivel)
.Select(s => new { s.NM_Usuario, s.Usuario1, s.Email }).ToList();
return Json(result_carrega_pagina, JsonRequestBehavior.AllowGet);
}
But, my web page do not work. What I must to do? This is the error: Failed to load resource: the server responded with a status of 500 (Internal Server Error)
How I solve this problem?
You controller takes in an int
, yet you pass in a JSON.stringify(ajaxParameter)
. It needs to be in this format:
data: { _nivel: 1 }
Check your network traffic and put a breakpoint to make sure it is in the right format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.