I am new to MVC, and I am working on a homework project where I need to make ajax call to a controller so I can select data from the database. When I make the ajax call I get 200 HTTP code but the I can't print what's in the success: in the ajax parameters. If anyone knows the solution to this, please help me. Thank you in advance
MVC controller
[HttpGet]
public JsonResult GetPasos(string pasos)
{
var patnici = _context.Patnici
.FirstOrDefaultAsync(m => m.PassporNo == pasos);
return new JsonResult(patnici);
}
Ajax call:
$(document).ready(function () {
$("input#PassporNo").on("input", function () {
var input = document.getElementById("PassporNo").value;
var regex = new RegExp("^[A-Z0-9]+$");
if (regex.test(input) && input.length === 8) {
//$("input#PassporNo").on("input", function () {
console.log("blabla")
$.ajax({
//base address/controller/Action
url: '/Patnicis/GetPasos/',
type: 'GET',
data:
//Passing Input parameter
{"pasos": $('input#PassporNo').val() }
,
success: function (result) {
console.log("Rabote ajax");
},
error: function (jqXHR, textStatus, errorThrown, data) {
alert(jqXHR.status);
alert(textStatus);
alert(errorThrown);
console.log(data)
}
});
return false;
}
});
});