I have been trying for few hours now to find out the solution of how to get a JSON object back:
This is my function in view together with everything I tried:
$(document).ready(function () {
$(".nav-link").click(function () {
var chairChosen = $(this).attr("data-id");
var perfDateId = $("#perfDate").attr("id");
var totalCost = $("#totalMoney").html();
window.alert(perfDateId);
$.ajax({
url: '/Booking/ReserveSeat1/?id=' + chairChosen + '&perfDateId=' + perfDateId,
type: 'GET',
dataType: 'json',
success: function (data1) {
$("#test").append(typeof data1);
$("#test").append(" notConverted" + data1.Number);
$("#test").append(" notConverted" + data1["Number"]);
var result1 = jQuery.parseJSON(data1);
$("#test").append("Converted jquery" + result1.Number);
$("#test").append("Converted jquery" + result1["Number"]);
var result2 = JSON.stringify(data1);
var object1 = data1;
$("#test").append("get object " + object1.Number)
$("#test").append("Converted parse" + result2.Number);
$("#test").append("Converted parse" + result2["Number"]);
},
error: function (error) {
$(that).remove();
DisplayError(error.statusText);
}
});
});
});
I want to mention data I don't want to send JSON data, I only expect to receive it.
The following code is in my controller:
[HttpGet]
public ActionResult ReserveSeat1(int id, int perfDateId)
{
BookSeatResult bookSeat = new BookSeatResult()
{
Number = 10,
Result = "a string"
};
return Json(bookSeat);
}
also tried returning a JSON response from controller.
it's an mvc web app in asp.net core.
Not to forget to mention that when i do the call the controller responds, and it does return an object type
POSTmethod.