Skip to content

Instantly share code, notes, and snippets.

@michaltakac
Created March 26, 2016 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaltakac/a870f2376da9d289da7b to your computer and use it in GitHub Desktop.
Save michaltakac/a870f2376da9d289da7b to your computer and use it in GitHub Desktop.
Server method for getting data through PHP script with Meteor
Meteor.methods({
getCars: function() {
var url = 'http://example.com/my-php-script.php';
var result = HTTP.post(url, {timeout:30000});
if(result.statusCode==200) {
var respJson = JSON.parse(result.content);
console.log("response received.");
return respJson;
} else {
console.log("Response issue: ", result.statusCode);
var errorJson = JSON.parse(result.content);
throw new Meteor.Error(result.statusCode, errorJson.error);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment