Question

For loading the google oauth client lib we have to use this script tag

<script src="https://apis.google.com/js/client.js?onload=load"></script>

where the load method will be called after client.js is loaded.

i am using dojo in my application

How can i load this using dojo?

i have tried with dojo/request/script but the callback method is taken by the dojo which is not able to modify

any help how i can do this,

Thanks

Was it helpful?

Solution

call back is sent to the deferred then parameter::

require(["dojo/request/script", "dojo/dom", "dojo/dom-construct", "dojo/json", "dojo/on", "dojo/domReady!"],

function (script, dom, domConst, JSON, on) {
    on(dom.byId("startButton"), "click", function () {
        domConst.place("<p>Requesting...</p>", "ret");
        script.get("http://ajax.googleapis.com/ajax/services/search/web", {
            jsonp: "callback",
            query: {
                "v": "1.0",
                "q": "internet kittens"
            }
        }).then(function (data) {
            //Call you function here, or deal with data
            domConst.place("<p>response data: <code>" + JSON.stringify(data) + "</code></p>", "ret");
        });
    });
});

Fiddle::http://jsfiddle.net/D49GP/

UPDATE You will not be able to use the normal dojo syntax for this one. The problem is that when dojo creates the callback for the then, it creastes the call back function in object.method format. This does not work because google is using window[nameoffunction] for the call back. So since you can manually add parameters for the script IO. use below:

  script.get("https://apis.google.com/js/client.js", {
            //jsonp: "onload",
            query: {
                onload:<callbackfunction>

            }
        })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top