Welcome Guest, Not a member yet? Register   Sign In
Returning view partials using AJAX and JSON
#1

[eluser]mattalexx[/eluser]
Okay, so I've been looking around for a solution to this problem for a while but I haven't found it.

Here's an example of the desired functionality: In a DIV tag with the ID of "big_image" is a big image of the product. In a DIV tag with the ID of "item_image_thumbs" are a few thumbnails of alternative views of that item. When the user clicks one of the thumbnails, an AJAX request is initiated. Server-side, some data is saved into the session that basically says, "Show item image 143 as the large image for item 64". So far, so easy. Now I need the AJAX to return HTML for both of the included DIVs. The "big_image" DIV needs an updated big image. The "item_image_thumbs" DIV needs a new list of thumbnails, with a darker border around the selected one.

I need to have the original AJAX call return a JSON array like the following:
Code:
{"partials":{
   "big_image":"{HTML FOR big_image DIV}",
   "item_image_thumbs":"{HTML FOR item_image_thumbs DIV}"
}}
With a JSON like this, I could easily write a general JS function that updates the DIV with the HTML present in the array.

Here's my question: In the controller, how do I load partial views into variables so that I can encode them into JSON and print them? What would be the best way to do this?


Messages In This Thread
Returning view partials using AJAX and JSON - by El Forum - 08-20-2008, 05:03 PM
Returning view partials using AJAX and JSON - by El Forum - 08-20-2008, 06:09 PM
Returning view partials using AJAX and JSON - by El Forum - 08-20-2008, 06:12 PM
Returning view partials using AJAX and JSON - by El Forum - 08-20-2008, 07:24 PM
Returning view partials using AJAX and JSON - by El Forum - 08-20-2008, 07:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB