I'm deploying a node.js based application to IBM's Bluemix and have added a few features to one of the samples they provide. I've added an additional javascript file that makes an ajax call to PHP, but the PHP file is coming back as not found because my path is incorrect. I've tried putting the file everywhere and it's just not being found. I'm thinking (as a total node noobie) that I'm missing some mysterious configuration or something.
In the main directory (among other things), the structure is like this:
-- views
- index.ejs (this is the main displayed code)
-- public
- js
- custom.js (my added file)
- all the other necessary js files
- css
- img
- php - I added this directory
- get-twitter.php - I added this...custom.js makes an ajax call here
In custom.js, I have this:
$("#get-twitter").click(function(event) {
handle = $('#twitter-handle').val();
$.ajax({
url: 'php/get-twitter.php',
type: 'POST',
dataType: 'JSON',
data: {
handle: handle,
},
success: function(data) {
console.log(data);
$.each(data, function(index, val) {
console.log(val.text);
});
}
});
});
When I try to make this call, the file isn't found, but the path is this: https://myapp.mybluemix.net/php/get-twitter.php
It should be in views/php/get-twitter.php
, but I'm guessing this is a configuration issue on my end.
I've tried every iteration of this: url: 'php/get-twitter.php',
and put the PHP file in every directory and nothing is working.
What am I missing here?
There is no way to run PHP scripts from node. You will need to set up a server that supports PHP, and make your requests there. One option would be Apache.
Realistically, you probably don't want to set up an entire server for the purpose of running a single PHP script. A more reasonable solution would be to port the PHP script to run on Node. There are many packages for twitter API integration on NPM (e.g. the twitter module).