【问题标题】:Javascript - how to load the javascript library while using Google App Engine?Javascript - 如何在使用 Google App Engine 时加载 javascript 库?
【发布时间】:2014-03-19 15:50:03
【问题描述】:

我正在使用 Python yaml 运行 Google App 引擎。 现在我需要使用 whichbrowser.net (whichbrowser 也使用 PHP 并且发生的错误在

但是当我尝试加载 http://whichbrowser.net/ 的 Javascript 库时,它在 detect.js 第 1 行上失败了“Uncaught SyntaxError: Unexpected token

detect.js:

<?php

    header("Content-Type: text/javascript");
    header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"); 
    header("Pragma: no-cache");
    header("Expires: 0"); 

    include('libraries/whichbrowser.php');

    $options = array('headers' => apache_request_headers());
    if (isset($_REQUEST['ua'])) $options['useragent'] = $_REQUEST['ua'];
    if (isset($_REQUEST['e'])) $options['engine'] = intval($_REQUEST['e']);
    if (isset($_REQUEST['f'])) $options['features'] = intval($_REQUEST['f']);
    if (isset($_REQUEST['w'])) $options['width'] = intval($_REQUEST['w']);
    if (isset($_REQUEST['h'])) $options['height'] = intval($_REQUEST['h']);
    $detected = new WhichBrowser($options);

?>

index.html:

  (function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
  e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
  e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
  f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
  p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
  s.src='/whichbrowser/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();

app.yaml:

- url: /whichbrowser
  static_dir: whichbrowser

【问题讨论】:

    标签: javascript php jquery python google-app-engine


    【解决方案1】:

    App Engine 上加载JavaScript 的方式没有什么特别之处。它的加载方式与在任何其他平台/服务器上的加载方式相同。

    【讨论】:

    • 我在浏览器中收到此错误:“Uncaught SyntaxError: Unexpected token <?php
    • paste.ubuntu.com/7120550 ,这是我的 yaml 文件。我怎么知道使用 python 和 php?
    • 我在我的 yaml 文件中运行运行时 main 作为 Python,您可以看到,但是 javascript 需要加载失败的 PHP 脚本,请您先详细检查一下。 Google App Engine 需要允许我从 index.html 访问 Python 运行时 + PHP 运行时,它只允许 Python 运行时。
    【解决方案2】:

    您的JS 文件包含PHP 处理指令。如果您的应用程序是用 python 编写的,这将失败。

    您可以使用PHP 编写您的应用程序,也可以使用Python 编写它。您不能在同一版本中混合使用两种语言。

    理论上,您可以使用模块/版本来实现 PHPPython 版本并使用调度路由将它们连接在一起,但我认为如果您只需找到一个浏览器检测库,它就会简单得多没有 PHP 语言依赖。

    有关模块和调度路由的更多信息: LINK

    【讨论】:

      【解决方案3】:

      仅供参考 - Google App Engine - 不允许 PHP + Python 同时运行。为此,您需要使用在另一台服务器上运行的 PHP 的 URL。

      这是一个真正的 Google App Engine 陷阱,因为当应用程序变大时,就无法移动。

      【讨论】:

        猜你喜欢
        • 2011-07-14
        • 1970-01-01
        • 1970-01-01
        • 2013-12-17
        • 1970-01-01
        • 2011-06-05
        • 2011-03-15
        • 1970-01-01
        • 2014-09-18
        相关资源
        最近更新 更多