Search code examples
jqueryjsonasp.net-mvc-4asp.net-coreasp.net-core-mvc

Trying to get JSON from MVC Controller and getting error net::ERR_INCOMPLETE_CHUNKED_ENCODING


I am trying to get JSON from my controller to use in jQuery. I have the following code. When I visit the URL in my browser it returns the json so I know that the controller is working... But I get the following

GET http://localhost:52802/Checkout/GetContactById?id=1 net::ERR_INCOMPLETE_CHUNKED_ENCODING

client-side jQuery

var theUrl = window.location.origin + '/Checkout/GetContactById?id=' + contactId;

$.ajax({
    url: theUrl,
    type: "GET",
    success: function (result) {
        alert("Success");
    },
    error: function (error) {
        alert("Error");
    }
});

Server-side Controller

[HttpGet]
public IActionResult GetContactById(int id)
{
  Contact contact = this.checkoutDataAccess.GetContactById(id);
  return Json(contact);
}

The only alert I get is "Error"

Update

After more research it looks like everything is loading... but I am getting an error

Failed to load response data

in the console.

I stepped through the code and everything works on the controller side. I am not sure if it is not formatting the JSON correct, or if I am not receiving it correctly. Either way I have no idea what is going on.


Solution

  • Actually you are getting the text Error since you put alert("Error"); Try alert(error); instead Or try debugging using firebug