1

好的,我试图调用一个名为“map.html”的文件

HTTP.call("GET",
 "/client/map.html",
          {},
          function (error, result) {
            if (result.statusCode === 200) {
              $("body").html(result.content);
            }
          });

文件代码是:

<template name="map">
    <div id="map-canvas" style="width: 1000px; height: 1000px;"></div>
</template>

如果我取出模板标签,应用程序将不会启动“client/map.html:1:HTML 模板中的格式错误”

但是添加模板标签也不起作用,我的 result.content 会返回一个空的 body 标签,我认为我缺少流星 http 调用的很大一部分。

请参阅下面的回复:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="/packages/accounts-facebook/facebook_login_button.css?7b6e74d628e59311774e7b3409bdc3686e70e788">
  <link rel="stylesheet" href="/packages/accounts-github/github_login_button.css?4b6d8c2193c93dddce919620b231b5a94e6a9faf">
  <link rel="stylesheet" href="/packages/accounts-twitter/twitter_login_button.css?b0667609964694bc045cfee5961cf78e761f82a5">
  <link rel="stylesheet" href="/packages/accounts-google/google_login_button.css?6636e1d8ac79bff54828e78df6e3d407e6b6c38e">
  <link rel="stylesheet" href="/packages/accounts-meetup/meetup_login_button.css?ea299301e151180110c73c0dad415573cdcc7d67">
  <link rel="stylesheet" href="/packages/accounts-ui/login_buttons.less.css?a6791c6bbc0dbffe1967f7603ad5e71a937da2f7">
  <link rel="stylesheet" href="/packages/bootstrap/css/bootstrap.css?e5976308949024b827360231c67b6f50ee1cf8c5">
  <link rel="stylesheet" href="/packages/bootstrap/css/bootstrap-responsive.css?b66c9c5bfb9556bf343298e3fe6e49c39db8c222">
  <link rel="stylesheet" href="/packages/bootstrap/css/bootstrap-override.css?15fa5b55da5c16ed92ffe0c85c0d6aa0867b9c7f">
  <link rel="stylesheet" href="/client/stylesheets/ie.css?55d03cbe8dc4482082815585822d80503557fdcb">
  <link rel="stylesheet" href="/client/stylesheets/print.css?5d4514803362274f0bd875bc5a9ba81d6e49dbb0">
  <link rel="stylesheet" href="/client/stylesheets/screen.css?02fad6adf7c3c0e3b20a75fc5ab594cb1343f993">


<script type="text/javascript">
__meteor_runtime_config__ = {"meteorRelease":"0.6.5.1","ROOT_URL":"http://localhost:3000/","ROOT_URL_PATH_PREFIX":"","serverId":"NDg93Twm6549DtLMW"};
</script>

  <script type="text/javascript" src="/packages/underscore.js?a1286cdb983623d4d035c8d7cd7a1e8e15274cf5"></script>
  <script type="text/javascript" src="/packages/meteor.js?701b92c6c05538cfff59c73f747498bf49ff73b1"></script>
  <script type="text/javascript" src="/packages/standard-app-packages.js?be7072e6abfda638502b63fa0f809c85c8c2b8ed"></script>
  <script type="text/javascript" src="/packages/random.js?a592658942f32ab31e84c4e67768f13f07a8e4b4"></script>
  <script type="text/javascript" src="/packages/jquery.js?1a9d113f1f0c905a877e6eb3d97b07a871baa416"></script>
  <script type="text/javascript" src="/packages/domutils.js?c5d4d4c5629038d1bb6deea7acd7a0512d406fe3"></script>
  <script type="text/javascript" src="/packages/liverange.js?b3097d72d458e645fd4f0021c8ff5189abe8d98a"></script>
  <script type="text/javascript" src="/packages/universal-events.js?5bfa39513d2caa4af4f829d7f4907afae3601adf"></script>
  <script type="text/javascript" src="/packages/ordered-dict.js?bf8af2f26c8d96bf8b2e6b407d3ed69f23c2cd37"></script>
  <script type="text/javascript" src="/packages/deps.js?5ac28feec1f3e0539889ecde598dd9d01e408b41"></script>
  <script type="text/javascript" src="/packages/json.js?e22856eae714c681199eabc5c0710b904b125554"></script>
  <script type="text/javascript" src="/packages/ejson.js?6798aba30085d088a96e75a363ca1a100b990bfd"></script>
  <script type="text/javascript" src="/packages/minimongo.js?e21b5896248d8b375979901f4f3d4907fd4cb99e"></script>
  <script type="text/javascript" src="/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab"></script>
  <script type="text/javascript" src="/packages/preserve-inputs.js?7b3b8bf0669f1f110126607ecd8488f719344f09"></script>
  <script type="text/javascript" src="/packages/localstorage.js?66e8e87ffe90dfe2f3f14d2f450a49ac7a33c5b8"></script>
  <script type="text/javascript" src="/packages/logging.js?e3df5be1604658260b4000a031f1a7b969cb6133"></script>
  <script type="text/javascript" src="/packages/check.js?a54cf3c7b3abe9208d064621eb80a3ecaf2f4add"></script>
  <script type="text/javascript" src="/packages/reload.js?acb1a2a618bdea7a55ce912cfcf348b9d89e0876"></script>
  <script type="text/javascript" src="/packages/livedata.js?a3d111217f95d5af907302198a85413d1acbaf05"></script>
  <script type="text/javascript" src="/packages/insecure.js?3dc9d4a2dad55999b5b15a447d57f3d5fb66b290"></script>
  <script type="text/javascript" src="/packages/mongo-livedata.js?a3509c5f9f4ed6ded19eaac97c69c2a91d81df81"></script>
  <script type="text/javascript" src="/packages/service-configuration.js?65f9d7f8c45ecc9be55a58180bf579558581a9dc"></script>
  <script type="text/javascript" src="/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b"></script>
  <script type="text/javascript" src="/packages/accounts-base.js?e991c6fc17941a584b1daa1eef54fc838068754e"></script>
  <script type="text/javascript" src="/packages/accounts-oauth.js?ec0c258ab408470b49f37de355c3b9b55fb044e4"></script>
  <script type="text/javascript" src="/packages/oauth.js?4aa2e1486aef79113cba73c17e8cad0e9f8d929d"></script>
  <script type="text/javascript" src="/packages/oauth2.js?228fb002a50ab94e17475623f0e34cd441d691ba"></script>
  <script type="text/javascript" src="/packages/templating.js?1003705ccf6a397e8fabce961be55b50108d109e"></script>
  <script type="text/javascript" src="/packages/facebook.js?d13866aba09795d6480224d2f506e89b4e7c179d"></script>
  <script type="text/javascript" src="/packages/accounts-facebook.js?9e890f917b8ec3c3ea39544407a7e982dbc6d5ae"></script>
  <script type="text/javascript" src="/packages/github.js?82beb1c17f04292f0007ab4c0a271e837424d8e6"></script>
  <script type="text/javascript" src="/packages/accounts-github.js?cd8e0996c426b07b63ab8131432e3cbb1bf3f6b9"></script>
  <script type="text/javascript" src="/packages/http.js?4aec4250e79a92408f1c5e234a52434907239586"></script>
  <script type="text/javascript" src="/packages/oauth1.js?471ab5c3f6f6f4fca945199077d8319ed535bb3c"></script>
  <script type="text/javascript" src="/packages/twitter.js?466fe5521ac996774043cc558d751833e3c0fbb3"></script>
  <script type="text/javascript" src="/packages/accounts-twitter.js?a1c5862c55c6bf951b845bee147062ac1d5fb3d4"></script>
  <script type="text/javascript" src="/packages/google.js?af3f209a9f621263be5c2ab68480825d47a142f6"></script>
  <script type="text/javascript" src="/packages/accounts-google.js?9ef9953d728cd324cfd7280e7b31c1b89ce5eed5"></script>
  <script type="text/javascript" src="/packages/email.js?911578310472ff10dca16a5306b7f455801d0f35"></script>
  <script type="text/javascript" src="/packages/meetup.js?27dd52a68bc2488380c4f3cebbc1448b2914524a"></script>
  <script type="text/javascript" src="/packages/accounts-meetup.js?e29b2fa08714acff3636e67fc28938f2a5bc0219"></script>
  <script type="text/javascript" src="/packages/srp.js?b67965acbe0e0f66edcf4df1e5d061dadedd4216"></script>
  <script type="text/javascript" src="/packages/accounts-password.js?7194b16ddb1435bc72cb2308aab74d326cf082ff"></script>
  <script type="text/javascript" src="/packages/reactive-dict.js?22667928acc72f619ce81e7ac1e35def1ba9e0ae"></script>
  <script type="text/javascript" src="/packages/session.js?5bcd2d86431dc10d5f4be0910cb6567342e1aaf6"></script>
  <script type="text/javascript" src="/packages/accounts-ui-unstyled.js?7ca43f42462f1bda8a5c7991bfc1e9e842828ca0"></script>
  <script type="text/javascript" src="/packages/less.js?7d1bf981a25a449d6270558bcfc983313c40cd26"></script>
  <script type="text/javascript" src="/packages/accounts-ui.js?1ff79db616cce9b320fe8aed6103eded31248467"></script>
  <script type="text/javascript" src="/packages/backbone.js?9e9aaec07c5a6cc1d46dfab6736beedcd71259dd"></script>
  <script type="text/javascript" src="/packages/bootstrap.js?86f8f0d5d5a274fd05c4a35c7a7dddb771ce2a0e"></script>
  <script type="text/javascript" src="/packages/autopublish.js?c3059a78bb200b171099fc4fa1a9345101790ddb"></script>
  <script type="text/javascript" src="/packages/iron-router.js?2f848a70f81fa257705f5ffa213d4eb31759e02d"></script>
  <script type="text/javascript" src="/packages/webapp.js?5c7d940d9baab5b893f7e5904e7258ef69e7ef8b"></script>
  <script type="text/javascript" src="/packages/global-imports.js?390198a974d86e88eddf36f797eba0d2aaade01b"></script>
  <script type="text/javascript" src="/client/template.map.js?3d91a27fae0def5953c035959799cf274961ab39"></script>
  <script type="text/javascript" src="/client/template.meetme.js?ddf3af8adada307ad03aab720c4b185bb6b64e44"></script>
  <script type="text/javascript" src="/client/fb.js?2a3453bba5b8f7e5a39caf4f0fb6016f1b588104"></script>
  <script type="text/javascript" src="/client/map.js?298fd731353fe8a877a6db486a1c4691ce75a412"></script>
  <script type="text/javascript" src="/client/meetmeClient.js?67fc7d1913fdc057997e14b359de6937b9da684c"></script>
  <script type="text/javascript" src="/meetme.js?7761ad0a01c156c23e392a90dda0efd3cf938eed"></script>
  <script type="text/javascript" src="/router.js?d7e47615c35b162cbbd2c1d5d16bb82aef52149e"></script>


<title>meetme</title>
    <script src="//connect.facebook.net/en_US/all.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" src="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
</head>
<body>

</body>
</html>
4

2 回答 2

1

当您GET调用 on 时/client/map.html,您执行的操作与浏览器/client/map.html在您的应用程序上输入路径时执行的操作相同。所以结果与浏览器得到的结果是一样的——渲染了整个 HTML 页面。所以你粘贴的结果是正确的。

你想在这里达到什么目的?

如果您尝试更改应用程序所在的路径并相应地显示模板,您可能应该查看 [router] 或 [iron-router] 包,它们可以轻松实现。你可以在没有包含window.location方法和聪明的模板助手的包的情况下做同样的事情,认为在大多数情况下它会重新发明轮子。您可能永远不想GET直接在 Meteor 应用程序中调用您自己的服务器。

于 2013-10-08T15:49:57.853 回答
1

您是否尝试将请求从客户端发送到另一台服务器?在大多数情况下这是不可能的。如果您需要从远程服务器获取数据并将其添加到您的模板中,您应该在服务器端进行此操作并将 html 连接到客户端并将 html 数据附加到您的模板中,如下所示

//client
Template.map.rendered = function(){
  Meteor.call('get_remote_html_data', function(err, res){
             if(res){$('your_selector').html(res)}
  });    
}

//server
Meteor.methods{get_remote_html_data: function(){return http.get(your_remote_url)}}
于 2013-10-09T09:16:48.210 回答