views:

400

answers:

6

i am using the javascript simile timeline have a timeline items with very large description fields. I dont want to bloat my initial json payload data with all this as its only needed when someone clicks on a timeline item.

So for example, on this JSON result:

 {
 'dateTimeFormat': 'iso8601',
 'wikiURL': "http://simile.mit.edu/shelf/",
 'wikiSection': "Simile Cubism Timeline",

 'events' : [

    {'start': '1880',
    'title': 'Test 1a: only start date, no durationEvent',
    'description': 'This is a really loooooooooooooooooooooooong field',
    'image': 'http://images.allposters.com/images/AWI/NR096_b.jpg',
    'link': 'http://www.allposters.com/-sp/Barfusserkirche-1924-Posters_i1116895_.htm'
    },

i would want to remove the description field all together (or send null) from the JSON and have it load it ondemand through another ajax call.

is there anyway to not send the desription field down during the initial load and when someone clicks on a timeline item have it load the description via ajax at that point

I thought this would be a common feature but i can't find it

A: 

That would be a server side issue. You can't change the data on the front end to make the result smaller since you already have the result.

Use a different call or add parameters.

mwilcox
@mwilcox - my question is fine for the server side as well. I have control over both sides. I want to see if there is a way to load the description content later when you click on a roadmap item. Its quite easy to not send down the description in the initial payload JSON.
ooo
+1  A: 

So I wonder if you could place a script call the description.

{
 'dateTimeFormat': 'iso8601',
 'wikiURL': "http://simile.mit.edu/shelf/",
 'wikiSection': "Simile Cubism Timeline",

 'events' : [

    {'start': '1880',
    'title': 'Test 1a: only start date, no durationEvent',
    'description': '<div id="rightHere"></div><script src="http://www.allposters.com/js/ajax.js"&gt;&lt;/script&gt;&lt;script&gt;getDescription("rightHere","NR096_b")&lt;/script&gt;',
    'image': 'http://images.allposters.com/images/AWI/NR096_b.jpg',
    'link': 'http://www.allposters.com/-sp/Barfusserkirche-1924-Posters_i1116895_.htm'
    },

Breaking it down a bit...

This is where you would update the innerHTML in you javascript:

<div id="rightHere"></div>

This is the javascript which makes the ajax call and updates the innerHTML:

<script src="http://www.allposters.com/js/ajax.js"&gt;&lt;/script&gt;

Finally, this is the javascript call to get the right description into the right location:

<script>getDescription("rightHere","NR096_b")</script>

I admit that I haven't tried this, but it may be a start.

dacracot
A: 

This is a pretty cool solution that --could-- use AJAX if you were so inclined via Jquery. Very nice result!

http://tutorialzine.com/2010/01/advanced-event-timeline-with-php-css-jquery/

bpeterson76
A: 

I'm assuming you're using PHP, and have the sample JSON in a String:

//I have the JSON string in $json::
$jsonArr = json_decode($json);
$jsonOput = array();

//move descriptions into a numbered array, (E.G. a JSON [])
foreach($jsonArr['events'] as $a=>$b) {
    $jsonOput[] = $b['description'];
    unset($jsonArr['events'][$a]['description'];
}

//Output the original JSON, without the descriptions
echo json_encode($jsonArr);
//Output the JSON of just the descriptions
echo json_encode($jsonOput);

Obviously you'd only output the description free, or the only descriptions; depending on what's requested.

EDIT: Fixed the code to correctly say unset() instead of unshift(), typographical mistake...

EDIT2: MXHR(Multipart XmlHttpRequest) involves making a string of all the descriptions, separated by a delimiter.

$finalOput = implode('||',$jsonOput);

And make a request for that long string. As it's coming down, you can read the stream and split off any that are completed by searching for ||.

Rixius
Let me know if this works for you.
Rixius
@Rixius - i dont follow what you are doing here. I can send the json query down to the client with out the description fine but i then need to load it when you click on a timeline item.
ooo
you would make a second AJAX request to download the description, I made the splitter to split out the description; you could also use MXHR http://about.digg.com/blog/duistream-and-mxhr to download all of the descriptions at once and split it as it's coming down. That way you only need 2 requests
Rixius
is this solution bearing into consideration the "javascript simile timeline" in question?
Brandon
Yes, because the descriptions are in the order they appear on the timeline, and as they come in, they are spliced up and placed into their slot, so when you clik on an entry, you either get a loading gif if it hasnt gotten there yet, or the description.
Rixius
@Rixius - a few things. I am using asp.net-mvc (not PHP). also, i dont follow how you are hooking into the event when you click on the timeline to grab the description at that point.
ooo
@Rixius - it doesn't seem like you're solving the problem @ooo has asked about. @ooo wants to know how to load the descriptions when events are clicked in his timeline.
Ryley
+2  A: 

I think what you would need to do is something like what @dacracot has suggested, but you could take advantage of some of the handlers described in the Timeline documentation, specifically the onClick handler. So what I'm imagining you do is this:

//save off the default bubble function
var defaultShowBubble = Timeline.OriginalEventPainter.prototype._showBubble;

//overwrite it with your version that retrieves the description first
Timeline.OriginalEventPainter.prototype._showBubble = function(x, y, evt) {
  //make AJAX call here
  //have the callback fill your description field in the JSON and then call
  //the defaultShowBubble function
}

There's at least one part I haven't answered, which is how to figure out which event was clicked, but you could probably figure it out from evt.getID()

EDIT: Oh the other tricky part might be how to insert the description into the timeline data. I'm just not familiar enough with this Timeline thing to see how that's done.

Ryley
A: 

I also had to do something like that in an asp.net MVC Application. In my case i had to do it on a page load. You can do it on some conditions\events too.

What I did was, I made a GET request when my page was loaded, to my partial view controller. From there I returned a "PartialViewResult". Then in the UI I placed it where it needed to be rendered. Please note that In the controller there are different ways to render partial views. I did not hard code the UI Html in the controller. That wouldn't be a good practice. I got the UI rendered by:

return PartialView("~/UserControls/Search.ascx", model);

Which is basically your view engine is rendering the UI Html. :) If you want to have a look at my implementation here is the link: http://www.realestatebazaar.com.bd/buy/property/search

Hope that helps.

Rahat