Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error invoking Method '': Method not found [404]

Tags:

meteor

In Meteor I get this error for every method I define on the client side:

Error invoking Method 'activeMenu': Method not found [404]

Just as an example, in my code, I have defined this method, like so:

/client/js/startup/methods.js

Meteor.methods({
    ...
    activeMenu: function() {
        if(Session.get('menu')) {
          $('.menu').removeClass('active');
          $('#' + Session.get('menu')).addClass('active');
        }
    },
    ...
});

and it is called from two place - when the application first get rendered, and after the router does its routing:

client/js/rendered.js

Template.ApplicationLayout.rendered = function() {
  Meteor.call('activeMenu');
}

/client/js/utils/router.js

Router.onAfterAction(function () {
  Meteor.call('activeMenu');
});

Each of the call evokes the error. However, the method still works, I am getting the results I expected, so the calls must have been successful, but I am still getting errors. These methods only runs on the client side, since they are for presentational purposes. I need the program to be error-free because I suspect that is the reason why spiderable isn't working.

like image 243
dayuloli Avatar asked Jan 02 '15 08:01

dayuloli


2 Answers

You have only the stub method when you use Meteor.methods you need a method on the server side, whereas the client side is optional to simulate latency compensation.

The way a Meteor call works is when you run a call it will immediately fire the client side one to simulate some UI effect while a response is returned from the server, then the server side call is fired.

This exists so that you can have a method where the response seems immediate, even though the server may actually take time to respond.

Since you don't have the corresponding server side method, when Meteor sends the call to the server it can't find it and responds with the error Method not found [404]

If you want to have a method where only the client side has an effect you should use a standard js method instead, without the var keyword to ensure its globally scoped (and can be accessed from other client side files)

activeMenu = function() {
    if(Session.get('menu')) {
      $('.menu').removeClass('active');
      $('#' + Session.get('menu')).addClass('active');
    }
}

Then in your other code:

activeMenu() instead of Meteor.call('activeMenu');

like image 173
Tarang Avatar answered Sep 21 '22 18:09

Tarang


I notice that the alphabetical names its important to load three calls method. I had the same problem when I have the next structure

server
  |----- dht-setup.js
  |----- methods.js

Then, dht-setup dont see the methods.js methods. Instead, I change the name of the file:

server
  |---- _methods.js
  |---- dht-sensor.js

The 404 Not found, resolve. The same issue I found in client side when a want to separate functions from templates, for example, separating D3js functions from the templates. You probably need ensure top of the alphabetical load using "underscore" character "_". Consider that, cause the examples work fine cause the methods are defined in STARTUP.JS, at leat alphabetical word.

like image 28
EdU Avatar answered Sep 21 '22 18:09

EdU