游.程 2016-02-18 22:29 采纳率: 0%
浏览 5

执行Sitecore ajax Get

I'm using Sitecore 7.0 to execute a get request that returns a Json result. I'm able to see the Json result but the request is responding with HTML and my JSON string is buried inside it all.

I'm believe that I have created the controller/item rendering incorrectly.

First I created a controller rendering where Controller Name and Controller Action are correctly filled out.

This is where I think I'm going wrong but have don't know where to go next. What I would do is create a Sitecore page and add that controller rendering to it. Currently the Generic template DOES have HTML to it that I'm seeing.

What is the correct way to include that controller rendering so that my controller action is hit in ASP MVC?

If I create an empty template and empty layout (blank .cshtml) would that correctly return my json string so that jquery ajax can parse it?

Or more generally, what is the correct way to execute GET request with JQuery ajax, Sitecore, and ASP MVC. I was using the following as a starting point and it worked for POST (returns JSON correctly) but I'm not sure what to do to get it to work for a GET request. http://www.bugdebugzone.com/2014/06/tutorial-how-to-make-ajax-call-in.html

  • 写回答

1条回答 默认 最新

  • weixin_33699914 2016-02-18 22:57
    关注

    Well, I guess I'll answer my own question since there wasn't a good response based on all my Google queries. If anyone feels there is a better way to do all this please chime in.

    First, the default JSON response provided by ASP MVC is limited so I found a link http://james.newtonking.com/archive/2008/10/16/asp-net-mvc-and-json-net that is a nice workaround.

    Second, my issue was that I was using a Generic template that had a header/footer in the layout. And this was causing the HTML to render instead of the JSON. So what I did was created an Empty Layout (I added a single placeholder in the cshtml to hold the json response) and Empty Template and created a Sitecore Page for them. After that it just worked.

    Here are other links I used to arrive at this answer.

    http://www.bugdebugzone.com/2014/06/tutorial-how-to-make-ajax-call-in.html

    评论

报告相同问题?