0
How to popular a table with a JSON
using XMLHttpResquest POST
?
Jquery
var xhr = new XMLHttpRequest();
xhr.open("POST", "/EnvioEmail/PlanilhaPaciente", { area: "Sistema" }, true);
xhr.addEventListener("load", function (Lista) {
//table que recebera o resultado do json
$('#conteudo-lista-envio-manual').html(Lista);
}, false);
xhr.addEventListener("error", function (Lista) {
msgErro;
}, false);
xhr.send(formdata);
C#
[HttpPost]
public JsonResult PlanilhaPaciente(HttpPostedFileBase planilha)
{
if (Request.Files["planilha"].ContentLength > 0)
{
var pacientes = new ContatosEmailModelView();
var msgerro = "";
if (ValidaPlanilha(planilha, out pacientes, out msgerro))
return Json(new { erro = false, Lista = pacientes.ListaContatos }, JsonRequestBehavior.AllowGet);
else
return Json(new { erro = true, msgErro = msgerro }, JsonRequestBehavior.AllowGet);
}
return Json(new { erro = true, msgErro = "Não existe registro no arquivo" }, JsonRequestBehavior.AllowGet);
}
Your question is very simple, if you can detail more, as for example, post the javascript object that goes to this request. And if there is any object on the server that represents your view object.
– Rodrigo K.B