Reputation: 30276
In this javascript code, I will submit a form to server, and waiting response data. After I get response from server, I will redirect to /list
Template.post_question_form.events({
'submit form' : function(event) {
event.preventDefault();
// get content value
var question = event.target.question_title.value;
var content = event.target.question_content.value;
// send data to server
Meteor.call('createQuestion', question, content, function(error, result) {
console.log(result);
Meteor.go('list');
});
}
});
But when my web application runs to line Meteor.go('list')
. I meet exception:
Exception in delivering result of invoking 'createQuestion': TypeError: undefined is not a function
at http://localhost:3000/client/views/post_question/post_question_form.js?ea61f464a8905bc8789871133dddf7b0782e7438:39:20
at Meteor.bindEnvironment [as _callback] (http://localhost:3000/packages/meteor.js?81e2f06cff198adaa81b3bc09fc4f3728b7370ec:977:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:3858:12)
at _.extend.receiveResult (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:3878:10)
at _.extend._livedata_result (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4931:9)
at onMessage (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:3723:12)
at http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:2717:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
at _.extend._launchConnection.self.socket.onmessage (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:2716:11)
And here is createQuestion
code:
Meteor.methods({
'createQuestion': function(title, content) {
// insert into database question object
return Topic.insert({
title: title,
content: content
});
}
});
Although I have tested localhost:3000/list
, no problem founds. I don't know how to solve this problem.
Thanks :)
Upvotes: 1
Views: 3228
Reputation: 4639
I think you need Router.go()
if you are using Iron Router. I don't know of a Meteor.go()
- Meteor does not ship with a router.
Upvotes: 4