weixin_33724046 2016-12-16 21:35 采纳率: 0%
浏览 60

使用Node.js的文件路径问题

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?

  • 写回答

2条回答 默认 最新

  • weixin_33709609 2016-12-22 02:39
    关注

    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).

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端