Take a look at picker.mit.edu, which does some of this programmatic json loading (you pick some departments initially, then while browsing there's a dropdown at top left that lets you "add more courses".
fractile81 wrote: > I'm helping out matt in > http://groups.google.com/group/simile-widgets/browse_thread/thread/731e105551685399/e6c492871cfe3f5d#e6c492871cfe3f5d > to try and get the app to run a bit smoother (the browser lag in FF is > terrible!). I've been playing with the idea of loading JSON in chunks > using a service that takes an offset, then adding the data to > Exhibit. This works, but is still really slow to load. > > What I would like to do is programmatically load each JSON chunk once > a successful request has been made. Here's what I think should work: > > /*================================================== > * Exhibit.ExhibitJSONChunkImporter > *================================================== > */ > > Exhibit.ExhibitJSONChunkImporter = { > }; > Exhibit.importers["application/json-chunk"] = > Exhibit.ExhibitJSONChunkImporter; > > Exhibit.ExhibitJSONChunkImporter.load = function(link, database, cont) > { > var url = typeof link == "string" ? link : link.href; > var last_chunk = -1; > var items = []; > url = Exhibit.Persistence.resolveURL(url); > > var fChunk = function(xmlhttp) { > try { > var o = null; > try { > o = eval("(" + xmlhttp.responseText + ")"); > } catch (e) { > > Exhibit.UI.showJsonFileValidation(Exhibit.l10n.badJsonMessage(url, > e), url); > } > > if (o != null) { > if (o.status == 'ok') { > last_chunk = o.chunk; > > > // THIS NEXT LINE DOESN'T WORK EVERY > TIME! > database.loadData(o, > Exhibit.Persistence.getBaseURL(url)); > > > if (last_chunk + 1 < o.chunks) { > return true; > } > } else { > > } > } > } catch (e) { > SimileAjax.Debug.exception(e, "Error loading Exhibit > JSON chunk > data from " + url); > } > > return false; > } > > var fError = function(statusText, status, xmlhttp) { > Exhibit.UI.hideBusyIndicator(); > Exhibit.UI.showHelp(Exhibit.l10n.failedToLoadDataFileMessage > (url)); > if (cont) cont(); > }; > > var fDone = function(xmlhttp) { > try { > if (fChunk(xmlhttp)) { > SimileAjax.XmlHttp.get(url + '?chunk=' + > (last_chunk+1), > fError, fDone); > } else { > Exhibit.UI.hideBusyIndicator(); > // Alternate database.loadItems(); can go here > } > } finally { > if (cont) cont(); > } > }; > > Exhibit.UI.showBusyIndicator(); > SimileAjax.XmlHttp.get(url, fError, fDone); > } > > In there I try to call database.loadData(); for each chunk of JSON I > receive. This works for the first couple of chunks (I have a lot of > chunks), but I eventually get the following errors: > > TypeError: this._dom is undefined "Error firing event of name > onItemsChanged" - debug.js (line 53) > Error firing event of name onItemsChanged "Error firing event of name > onAfterLoadingItems" - debug.js (line 53) > Database.loadItems failed "Error firing event of name > onAfterLoadingItems" - debug.js (line 53) > Error loading Exhibit JSON chunk data from http://<pathtoservice>/chunk.php > "Error firing event of name onAfterLoadingItems" - debug.js (line 53) > Error firing event of name onAfterLoadingItems "XmlHttp: Error > handling onReadyStateChange" - debug.js (line 53) > > So I have two questions: 1) is database.loadItems(); capable of adding > data over multiple calls like I was hoping, or is there another > function/process I should try using? 2) I'm assuming the errors I'm > getting are related to my using the database.loadItems(); function the > way that I am -- is this assumption correct, or is there another place > I should be looking (apologies, I don't know this code very well yet)? > > Thanks for any input! > -Craig > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SIMILE Widgets" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/simile-widgets?hl=en -~----------~----~----~----~------~----~------~--~---
