views:

504

answers:

3

How do I use Google autoload functionality to automatically load JQuery?

http://code.google.com/apis/ajax/documentation/autoloader-wizard.html

Reading the documention, I thought the below would work but doesn't.

<script type="text/javascript" src="http://www.google.com/jsapi?autoload={"modules":[{name:"maps",version:3,{name:"maps",version:3,other_params:"sensor=false"},{"name":"jquery","version":"1.3.2"},{"name":"jqueryui","version":"1.7.2"}]}"&gt;&lt;/script&gt;

However, the above code does not work, even if I encode the URL as:

<script type="text/javascript" src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7Bname%3A%22maps%22%2Cversion%3A3%2C%7Bname%3A%22maps%22%2Cversion%3A3%2Cother_params%3A%22sensor%3Dfalse%22%7D%2C%7B%22name%22%3A%22jquery%22%2C%22version%22%3A%221.3.2%22%7D%2C%7B%22name%22%3A%22jqueryui%22%2C%22version%22%3A%221.7.2%22%7D%5D%7D"&gt;&lt;/script&gt;
A: 
rockacola
I've updated my original post. I'm using Google Maps 3 (so no api key needed), JQuery (1.3.2) and JQueryUI (1.7.2). However, the code in my original post does not work. Any ideas why?
TeddyR
+1  A: 

Go to Firefox -> Firebug -> Console Panel. Expand console input prompt on right side

Run this javascript code:

'http://www.google.com/jsapi?autoload='+encodeURIComponent(JSON.stringify({
  "modules" : [
    {
      "name" : "jquery",
      "version" : "1.3.2"
    },
    {
      "name" : "jqueryui", 
      "version" : "1.7.2"
    }
  ]
}))

It outputs final URL into console like this:

http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22jquery%22%2C%22version%22%3A%221.3.2%22%7D%2C%7B%22name%22%3A%22jqueryui%22%2C%22version%22%3A%221.7.2%22%7D%5D%7D

You may experiment with various settings as documented here: http://code.google.com/apis/ajaxlibs/documentation

Darwin
Don't forget to add Google Maps v3 with sensor=false
TeddyR
@Darwin, you'll see in my updated original post that my code is very similar and does not work. Any ideas?
TeddyR
When I put final url into Firefox addressbar and load that script, it looks good. Last two lines are google.load("jquery","1.3.2",{}); and google.load("jqueryui","1.7.2",{}); so I expect you have bug somewhere else.
Darwin
Official docs speak only about using Google Maps API version 2 and 2.x (http://code.google.com/apis/ajax/documentation/#AvailableAPIs)
Darwin
@Darwin, Google Maps API v3 is officially supported. Go to http://code.google.com/apis/maps/documentation/v3/demogallery.html see the Autoload example for v3. -->http://gmaps-samples-v3.googlecode.com/svn/trunk/commonloader/autoload.html
TeddyR
A: 

I found the answer, it's:

<script type="text/javascript" src="http://www.google.com/jsapi?autoload={"modules":[{name:"maps",version:3,other_params:"sensor=false"},{"name":"jquery","version":"1.3.2"},{"name":"jqueryui","version":"1.7.2"}]}"&gt;&lt;/script&gt;

encoded:

<script type="text/javascript" src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7Bname%3A%22maps%22%2Cversion%3A3%2Cother_params%3A%22sensor%3Dfalse%22%7D%2C%7B%22name%22%3A%22jquery%22%2C%22version%22%3A%221.3.2%22%7D%2C%7B%22name%22%3A%22jqueryui%22%2C%22version%22%3A%221.7.2%22%7D%5D%7D"&gt;&lt;/script&gt;
TeddyR