Script Libraries not loading when using AJAX

In one case the URLs for script libraries are being appended with a random value. In another case, the scrpit tags are rendered with extraneous characters.

I have a form that, when rendered on the web, brings in several other forms using JQuery ajax, and those documents are appended to the HTML. Everything on this screen is read-only. When a user wants to edit one of the documents, that doc is opened in an iFrame (using JQuery thickbox). I have all of my JQuery scripts in a separate database.

In the HTML Head I’m using the following code to calculate the JQuery URLs:

JQuery := Path + “/JQuery.nsf/”;

“<script language="JavaScript" type="text/javascript" src="” + JQuery + “jquery.js” + “">”

Calculating the library paths this way works for the main document, and individual documents in iframes, but errors out for all of the forms called via ajax. This is what Firebug shows me for a URL that fails:

http://[SERVERNAME & PATH]/JQuery.nsf/jquery.js?_=1205187380087

so…

I tried another way. Instead of putting the ”

is rendered

gets rendered as

<script src="/OneBeacon/Design/JQuery.nsf/jquery.curvycorners.packed.js" type="text/javascript" language=“JavaScript”>

In the first case, why is there something being appended after the “.js”?

In the second case, why are the script tags being rendered with extraneous “” characters?

Subject: It’s because your URL isn’t valid…

You are not loading the js file from the file system you are loading it from a database, so you need a little change, as ?_ is not a valid url command against a Domino resource.

http://[SERVERNAME & PATH]/JQuery.nsf/jquery.js?_=1205187380087

It should be:

http://[SERVERNAME & PATH]/JQuery.nsf/jquery.js?OpenJavascriptLibrary&_=1205187380087

The reason something is appended to the command is that browser cache requests and it thinks it has called it once already so why call it again, by appending the date time value the URL is always retrieved again so not cached.

As for the funky characters, did you type the text directly into notes, or did you cut and paste from another program?

Subject: RE: It’s because your URL isn’t valid…

When the mian page loads, all of the scripts load. I get errors when I’m calling in HTML of other forms via ajax.

Also, I don’t want the libraries to be loaded again. It’s taking too long. I want them to point to the library already loaded.

What I decided to do is since I’m opening forms in an iFrame in edit mode and bringing them into the main page in read mode, I’ll just hide the libraries via @IsDocBeingEdited.

Still, for future reference, is there anything I can do to prevent the problem?

Subject: RE: It’s because your URL isn’t valid…

JQuery is appending the unique identifier to get around browser and proxy caching – without it, the browser will never see changes on the server in the second and subsequent calls to a given URL (particularly in IE7). Just append ?Open to the JS library URL and JQuery should modify the href. As has been pointed out, though, the library will be forced to reload. Don’t like that behaviour? Then use inline JavaScript to write the script tag when the page is rendered. JQuery should not recognize the href, and so should not modify it.

That being said – why are you using AJAX to get a page that is going to load in its own container/window? Just open the darned thing.

Subject: RE: It’s because your URL isn’t valid…

Re: That being said – why are you using AJAX to get a page that is going to load in its own container/window? Just open the darned thing.

I have to take several forms from multiple databases and put them into a single UI/web page, with all forms as read only. When a user wants to edit a particular doc, which is in some cases a grid, the form is opened in edit mode within an iFrame. I could have used DBLookups and then parsed the data, but in some cases what is returned was greater than the (32?)K limit. I don’t remember the exact error.

How would you recommend I bring multiple forms into a single web UI?

Subject: RE: It’s because your URL isn’t valid…

If you are putting multiple Notes documents on a single web page, you only need to load the JQuery library once on the main page – there is no need to even try to load the element from each of the document URLs you are fetching (for one thing, that will invalidate the entire HTML document anyway). Just put each doc into its own div – you can copy the content of the over, but you’d need to rename the form in each case if you need editable forms.

Subject: RE: It’s because your URL isn’t valid…

I did change the code to not call the libraries but I have one last question, which I asked in another post today. If the form is not being rendered in edit mode, domino doesn’t apply a name attribute to the form tag. My web page contains form x, form y and as many of form z as may apply. I know of many ways to get form “z”. I know I could add a formname field, grab all elements with that field name and when the value = “z”, I can bubble up to the form element.

My preferred method would be to look for form tags where the name attribute is “z”. Can I force the form name to render?

Subject: RE: It’s because your URL isn’t valid…

No, and you don’t want to. Trust me – multiple forms with ambiguous names are NOT going to work. You want to give each form a unique HTML name. But if you aren’t editing, why are you using form tags at all? Domino may be serving them when you load the pages, but you hardly need them for printing or viewing, and since you are writing the HTML there is no reason to include the form tags at all.