Mam ustawiony routing:
routes.MapRoute(
"Przyklad",
"Przyklad",
new {controller = "Przyklad", action = "Index" },
new[] { typeof(PrzykladController).Namespace });
Kontroler:
public class PrzykladController : Controller
{
public ActionResult Index()
{
return View("Przyklad");
}
public JsonResult GetList()
{
return this.Json(new
{
success = "Sukces",
});
}
}
Skrypt z widoku Example.cshtml:
<script>
var locations = null;
$(document).ready(function () {
$.ajax({
url: '@Url.Action("GetList")',
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (response) {
console.log(response);
locations = response;
alert("Udało się pobrać dane");
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
});
</script>
Przy ładowaniu widoku niby wyświetla mi, że udało się załadować dane, jednak jak debuje to nie wchodzi mi do metody GetList i nie pobiera tego jsona.