0

I tring use Ajax get method but I took 500 Internal server error. I am using the following:

Cronom.Server.Connect = window.Cronom.Server.Connect || {};

(function (connect) {
    connect.AjajGet = function (getUrl, successFunc) {
        debugger;
        $.ajax(getUrl, {
            type: "GET",
            contentType: 'application/json; charset=utf-8',
            success: successFunc
        });
    };
})(Cronom.Server.Connect || {});

I call this function in page:

var list = Cronom.Server.Connect.AjajGet('/Home/GetFirstData', function(data) {
    console.log(data);
});

Server action has a [HttpGet] attribute. Where is my mistake?

Salih KARAHAN
  • 299
  • 1
  • 4
  • 18
  • possible duplicate of [500 Internal Server Error in ASP.NET MVC](http://stackoverflow.com/questions/2996139/500-internal-server-error-in-asp-net-mvc) – CodingIntrigue Aug 29 '14 at 10:12
  • The error is generated in the `GetFirstData()` method - probably throwing an exception somewhere, but you haven't posted that so impossible to tell –  Aug 29 '14 at 10:20
  • I fix this problem. My mistake is i don't use JsonRequestBehavior. old: return Json(new {statu = true, result}); new: `code` return Json(new {statu = true, result}, JsonRequestBehavior.AllowGet); – Salih KARAHAN Aug 29 '14 at 10:40
  • Why are you claiming `contentType: 'application/json; charset=utf-8',`? You're making a GET request. There is no request body to describe the content-type of! – Quentin Nov 03 '14 at 13:29

1 Answers1

0

I fix this problem. My mistake is i don't use JsonRequestBehavior.

old:

return Json(new {statu = true, result});

new:

return Json(new {statu = true, result}, JsonRequestBehavior.AllowGet);
Salih KARAHAN
  • 299
  • 1
  • 4
  • 18