Main problem I see there is that you are not waiting for the applet to initialize. You need to do that call from within an appletReadyCallback function.

On Tue, Aug 28, 2012 at 3:04 AM, Mikko Rantalainen <> wrote:
2012-08-24 17:07 Europe/Helsinki: Robert Hanson:
> On Fri, Aug 24, 2012 at 3:26 AM, Mikko Rantalainen
> <> wrote:
>> Is it possible to configure JmolApplet to fetch the required files
>> through the UA (web browser) instead of directly trying to connect the
>> server?
> I believe so. If you can get it through AJAX, you are all set. Just
> use Jmol-JSO.
> You should create a new _Applet prototype function on your page:
>   Jmol._Applet.prototype._getSecureFile = function(query, script){
>   this._script("zap;set echo middle center;echo Retrieving data...");
>   // script is necessary only if you need to do the post-load processing
>   var self = this;
>   Jmol._contactServer("?query=" + encodeURIComponent(query),
>    function(data){self._loadModel(data, ";" + script)},
> function(){alert("error...")}
>   );
>  }
> and call that from your page link.

I didn't follow what you mean with "page link".

> Then be sure to set  Info.serverURL to your server, not mine!

Sure. In fact, I used _ajax() directly and never even use serverURL. See

> Info.serverURL needs to point to a PHP document on your server to
> process your request for the "query" -- just deliver the file contents
> as is. In this way, the actual data files need never be exposed. Only
> your PHP file needs exposure.

I wonder what I did wrong. Here's the code I'm trying to use:

// We'll need to call Jmol._ajax() but it's an internal
// method. We workaround the issue by adding a new
// public method to Jmol object that calls the internal
// method for us.
Jmol._Applet.prototype._loadModelIndirect = function(url, script)
   set echo middle center;\
   echo Loading model via user agent...");

  var self = this;
  var info =
   dataType: "text",
   type: "GET",
   url: url,
   success: function(a)
    Jmol._loadSuccess(a, function(data){
     self._loadModel(data, ";"+script);
   error: function()
     alert("error: "+e)

var Info = {
 color: "#FFFFFF", // background color
 width: "100%",
 height: "100%",
 script: "language=\u0022fi\u0022;",
 use: "Java WebGL",
 jarPath: "/path/to/jmol/13.0.1",
 jarFile: "JmolApplet.jar",
 isSigned: false,
 //debug: true,

myJmol = Jmol.getApplet("JmolView", Info);
myJmol._loadModelIndirect("http://path/to/molecule.jmol", "");

The URL in _loadModelIndirect() will return the actual data only if
correct "session-id" is passed as a cookie.

I see that the browser is correctly downloading the molecule
and Jmol._loadModel() will be called with first parameter set
to the contents of the file and second parameter is set to
an empty string.

I can then trace the execution to Jmol._Applet.prototype._loadModel() in
 JmolApplet.js (from Jmol version 13.0.1) using Firefox 14 and
Firebug. The browser then executes

Jmol._Applet.prototype._loadModel = function(mol, params) {
var script = 'load DATA "model"\n' + mol + '\nEND "model" '
+ params;

Here the call 'this._applet.script()' will be passed a very long
 string (around 170 KB):

    'load DATA "model"\nMODEL_FILE_CONTENTS\nEND "model" ;'

where MODEL_FILE_CONTENTS is the actual file contents from correct .jmol
file (techically a ZIP archive).

Then nothing happens. The red message "Loading model via user
agent..." stays in the middle of the applet with zero CPU usage.

Do I need to do something else after calling Jmol._loadModel() inside
the ajax callback to get the model visible?


Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
Jmol-users mailing list

Robert M. Hanson
Larson-Anderson Professor of Chemistry
Chair, Chemistry Department
St. Olaf College
Northfield, MN

If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900