0

I am calling a controller action through $.getJSON() method but i dont know why the action is not calling.

$.getJSON("/Home/Index", { ID:id }, function(){
});

But when i change this to

$.getJSON("/Home/Index/s", { ID:id }, function(){
});

it works fine. I have check my routing and i did not find any problem there. What can be the issue?

2
  • Could you show your routing configuration? Commented Feb 27, 2011 at 15:39
  • routes.MapRoute( "GetPostTypeChild", "Home/Index", new { controller = "Home", action = "Index" } ); Commented Feb 28, 2011 at 7:22

1 Answer 1

1

That's really really weird.
I've tried your script and the only problem I can see is the fact that ASP.NET MVC2 can't return json data when the call is a GET. It's been blocked for security reasons.

If you try to trace your call with Fiddler, you might notice that the response is something like this:

"This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."

If you want to enable the return data, anyway, you can force it:

return (Json(<your object>, JsonRequestBehavior.AllowGet));

or do a POST. You can find more infos here.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes i face that issue but my problem is that the Index action is not calling.
Even with AllowGet, I found that it is called only one.. To overcome, I used [OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
@Fraz Sundal: it seems to me that your problem might be with the routing. Is this the only route defined? routes.MapRoute( "GetPostTypeChild", "Home/Index", new { controller = "Home", action = "Index" } );

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.