Asp.net mvc jQuery $ .post works, but $ .get doesn't

Why POST

does it work, but not GET

? I am not using [AcceptVerbs(HttpVerbs.Post)]

. I call this:

public ActionResult GetTest(string key)
        {
            var test = new { HelpTest = key };
            return Json(test);
        }

      

And it works when I do this:

$.post("/Home/GetTest", { key: options.key },
                        function(helpTest) {
                            alert(helpTest.HelpTest);
                        });  

      

But not this:

$.get("/Home/GetTest", { key: options.key },
                            function(helpTest) {
                                alert(helpTest.HelpTest);
                            });  

      

What was it for? Usage GET

returns XMLHttpRequest.status

from 500. What's confusing me?

+2


a source to share


1 answer


because return json does not return json to receive requests, it is unsafe and you should avoid it, but if you really want to use it, use the json overload to set the allowget property then it will work



return Json(data, JsonRequestBehavior.AllowGet);  

      

+3


a source







All Articles