Call server method in Meteor.js
The user put the URL in the WEB form and I want to get page title.
So I have the event-handler for my input field:
Template.new_bookmark.events({
// add new bookmark
'keyup #add-bookmark' : function(e,t) {
if(e.which === 13)
{
var url = String(e.target.value || "");
alert(url);
if(url) {
Meteor.call("getTitle", url, function(err, response) {
//var title = $(response.content).find("title").text();
var url_title =
response.content.match(/<title[^>]*>([^<]+)<\/title>/)[1];
//alert(url_title);
bookmarks.insert({Name:url_title,URL:url,tags:[]});
});
}
}
}
});
And the server method to get the page title:
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
Meteor.methods({
getTitle: function(url) {
var response = Meteor.http.call("GET", url);
return response;
}
});
});
}
When I put the URL I get alert message with my URL (it is correct) and
error message in the console:
I202303-11:56:14.490(4)? Exception while invoking method 'getTitle'
TypeError: Cannot call method 'call' of undefined
I202303-11:56:14.490(4)? at Meteor.methods.getTitle
(app/start_page.js:27:36)
I202303-11:56:14.491(4)? at maybeAuditArgumentChecks
(packages/livedata/livedata_server.js:1358)
I202303-11:56:14.491(4)? at
_.extend.protocol_handlers.method.exception
(packages/livedata/livedata_server.js:606)
I202303-11:56:14.491(4)? at _.extend.withValue
(packages/meteor/dynamics_nodejs.js:31)
I202303-11:56:14.491(4)? at packages/livedata/livedata_server.js:605
I202303-11:56:14.491(4)? at _.extend.withValue
(packages/meteor/dynamics_nodejs.js:31)
I202303-11:56:14.491(4)? at _.extend.protocol_handlers.method
(packages/livedata/livedata_server.js:604)
I202303-11:56:14.492(4)? at _.extend.processMessage.processNext
(packages/livedata/livedata_server.js:498)
Why I can not call the server method ?
This code worked fine, but I get error after updated meteor.js to the last
version.
No comments:
Post a Comment