1

I'm using ajax call with Jquery but it doesn't look to be right.

I call a controller:

$.ajax({
                    url: "http://urlWithpropperParams.com",
                    cache: false,
                    type: "GET",
                    dataType: "json",
                    traditional: true,
                    success: function (result) {
                        if(result.isEdited)
                        {
                            alert('No error');
                            window.location.href = 'http://myurl.com';
                        }
                        else
                        {
                            alert('Error');
                            //html(result.message);
                        }
                    }
                });

That controller is called and retuen Json Object (I put a breakpoint on it and it looks fine):

public JsonResult EditAuthority(string id, bool value)
        {
...
            return Json(new { isEdited = true, message = "" });
        }

The success part of the jquery ajax call must make something, but nothing is happening, and I see no error on console in my browser.

What is my mistake? Thanks in advance.

clement
  • 4,204
  • 10
  • 65
  • 133

1 Answers1

1

You are performing an HTTP GET with a JSON payload.

By default, the ASP.NET MVC framework does not allow you to respond to an HTTP GET request with a JSON payload. If you need to send JSON in response to a GET, you'll need to explicitly allow the behavior by using JsonRequestBehavior.AllowGet as the second parameter to the Json method.

Source: https://stackoverflow.com/a/8464685/84395

Try adding AllowGet to your response:

return Json(new { isEdited = true, message = "" }, JsonRequestBehavior.AllowGet);
Community
  • 1
  • 1
Andy T
  • 10,223
  • 5
  • 53
  • 95