Method call failed '': method not found [404]

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

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

As an example, in my code I defined this method, for example:

/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 places - when the application first receives the visualization, and after the router performs 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 call causes an error. However, the method still works, I get the expected results, so the calls should be successful, but I still get errors. These methods work only on the client side, as they are intended for presentation purposes. I need a program without errors, because I suspect that is why spiderable does not work.

+6
source share
2 answers

You only have a stub method, when you use Meteor.methods , you need a server-side method, while the client side is optional for modeling delay compensation.

How a Meteor call works, when you start a call, it immediately launches the client side to simulate some user interface effect when the response is returned from the server and then calls the call on the server side.

This exists, so you may have a method in which the response seems immediate, even if the server needs time to respond.

Since you do not have a corresponding method on the server side, when Meteor sends a call to the server, it cannot find it and responds to the Method not found [404] error Method not found [404]

If you want to have a method in which only the client side acts, you should instead use the standard js method, without the var keyword, to ensure its global coverage (and you can access it from other files on the client side)

 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');

+15
source

I noticed that in alphabetical order, it is important to load three call methods. I had the same problem when I got the following structure

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

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

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

404 Not found, decide. The same problem that I found on the client side when you want to separate functions from templates, for example, separating D3js functions from templates. You probably need to provide the top of the alphabetical load using the underscore character "_". Note that since the examples work fine, the methods are defined in STARTUP.JS, in the alphabetical word.

+1
source

Source: https://habr.com/ru/post/980425/


All Articles