2

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 500. What am I confused about?

1 Answer 1

3

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);  
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks - what are the concerns w/ returning JSON to a GET request?
It is open to hacker attacks look at this video if you are interested in learning more about security live.visitmix.com/MIX10/Sessions/FT05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.