From: Rolf H. <rh...@fl...> - 2011-11-23 15:54:52
|
On 11/23/2011 04:01 PM, Tamas Hegedus wrote: > Hi, > > I try to setup a webpage, where the structure in a jmol applet is > initialized by a json call back to the server. Sometimes the structure > is displayed, sometimes not. Sometimes (most of the times) "refresh" > helps. I think that there might be a problem with the asynchronous call > to the server and the pdb string does not arrive in time... But I can > not see this... I think that I have taken care about this. > > Do you have any idea? Have you seen something like that before? > Please see parts of the code below. > > Thanks for your help in advance, > Tamas > > ----------------- > THIS IS IN THE HTML: > <body> > <div id="projectJmolDiv"> > <script type="text/javascript"> > MyJmolInit(); > </script> > </div> > ETC... > > ----------------- > THIS IS IN myfunctions.js > > function jmolAppletLoaded() { > $.getJSON("getPdbString", function(pdb_string) { > jmolLoadInlineScript( pdb_string, "cpk off; wireframe off; cartoon; > color cartoon gray;", "Nezegeto"); > }); > }; > > function MyJmolInit() { > jmolInitialize("jmol"); > jmolSetAppletColor("white"); > jmolApplet(["100%", "100%"], "javascript jmolAppletLoaded();", > "Nezegeto"); > }; > I guess the '$.getJSON' is from the 'jQuery' API. I havn't used 'jQuery' yet for doing AJAX but if you look at the API (http://api.jquery.com/jQuery.getJSON/) it seems to me that the 'success' part is missing in your code. If the 'success' state is not reached fast enough (which might be achieved after the refresh by caching) the 'pdb_string' will presumably be still empty and it will not work. So you must make sure that the AJAX request was finished successfully before you try loading the structure. Regards, Rolf |