无法让jsonp在Closure中工作

时间:2016-01-05 18:10:08

标签: jsonp google-closure

我有一个简单的django Web服务器,它使用Closure执行跨域Web服务api调用。但是,我不知道如何加载goog.async。

这是代码:

    <!DOCTYPE html>
    <html>

    <head>

    <title>Closure Lab - goog.net.Jsonp</title>

    <script src="{% static "js/closure/goog/base.js" %}"></script>
    <script>
      goog.require('goog.dom');

      // Not sure how to fully specify Jsonp. Tried all sorts of component,
      // but, always fail inside Closure function
      //
      // goog.net.jsloader.load = function(uri, opt_options) {
      //     ...
      //     var deferred = new goog.async.Deferred(goog.net.jsloader.cancel_, request);
      goog.require('goog.net.jsloader');  
      goog.require('goog.net.Jsonp');

    </script>
    </head>
    <body  onload="myTest()">
    <script>

    var good = function (data) {
      alert('good:' + data);
    };

    var err = function (data) {
      alert('bad: ' + data);
    };

    function myTest() {
        var request = new goog.net.Jsonp('http://httpbin.org/get');
      request.send(null, good, err);
    }


    </script>
    </body>
    </html>

Closure库目录是../ static / js / closure。

失败在Closure库中:

  goog.net.jsloader.load = function(uri, opt_options) {
    var options = opt_options || {};
    var doc = options.document || document;

    var script = goog.dom.createElement(goog.dom.TagName.SCRIPT);
    var request = {script_: script, timeout_: undefined};
    var deferred = new goog.async.Deferred(goog.net.jsloader.cancel_, request);

    goog.async = unknown

如何指定Closure Jsonp库?任何评论都表示赞赏。

0 个答案:

没有答案