I am using this API to perform CRUD database operations in my meteor application. Till now, every operation is performed nicely.
Now consider a use case where some error occurs (eg. some validation error like invalid parameter) then I want to send the error object to the php script through jQuery ajax call.
So the question is: How to post the object to php from NodeJs script?
I have tried adding Meteor’s default jquery package by meteor add jquery. and then done something like this:
var $ = require('jquery');
....
....
function test(data){
console.log('test'+JSON.stringify(data));
$.post({
type: 'POST',
url: 'http://vibsy.com/test/chest.php',
data: data,
success: function(data) {
console.log(data);
}
});
}
But this shows the error:
ReferenceError: require is not defined
at app\server\collectionapi.js:1:10
Any ideas?
Jquery works well from the client side, im not too sure it will work on the server end. If you performed
meteor add jqueryyou don’t have to userequire. Meteor will automatically reference the correct js files ready to use. Remove the line below (client only) and it should be good to goIf your script is running on the server, which it looks like it is. Its better to use Meteor.http. Run
meteor add httpand use something like:Or more comfortably (sync):