0

I'm using Meteor. I need to get and display data from a site. I'm trying to do this with jQuery, but is not working. What do I do? There is a native of Meteor method to do this?

Example:

Template.test.helpers({
  load: function () {
    $(".first").load("http://www.jekyllrb.com");
  return $(".p")}
});

<head>
  <title>test</title>
</head>

<body>
  <h1>Welcome to Meteor!</h1>

  {{> test}}
</body>

<template name="test">
  {{load}}
</template>

The result is the array [object] [Object]. What is the solution?

Cláudio Júlio
  • 365
  • 4
  • 16

1 Answers1

0

Two solutions come to my mind.

The first solution:

Use onRendered hook:

Template.test.onRendered(function() {
  $(".first").load("http://www.jekyllrb.com");
});

You have to have an element with class first in your template:

<template name="test">
  <div class="first"></div>
</template>

The second solution:

Use iframe:

<template name="test">
  <iframe src="http://www.jekyllrb.com"></iframe>
</template>

EDIT: You may get "No 'Access-Control-Allow-Origin' header is present on the requested resource." error when you try to load page with $(".first").load("http://www.jekyllrb.com"); I made it work omitting www:

Template.test.onRendered(function() {
  $(".first").load("http://jekyllrb.com");
});
Community
  • 1
  • 1
Tomas Hromnik
  • 2,190
  • 13
  • 21