开发者

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

Why would POST work but not GET? I'm not using [AcceptVerbs(HttpVerbs.Post)]. I'm calling 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);
                            });  

Why would this be? Using GET returns an XMLHttpRequest.status of 50开发者_如何学编程0. What am I confused about?


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

return Json(data, JsonRequestBehavior.AllowGet);  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜