从 NodeJS 调用 PHP 方法 [英] Call PHP methods from NodeJS

查看:82
本文介绍了从 NodeJS 调用 PHP 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 PHP 的 API,可以为 Ajax 请求发送 JSON 数据.

I have a working PHP based API that sends JSON-Data for Ajax requests.

我想知道是否有任何方法可以从 NodeJS 调用这些 PHP 文件,甚至可以通过 Ajax 请求调用,所以我不必重写所有代码.

I wonder if there is any way to call those PHP Files from NodeJS, maybe even by an Ajax Request, so i don't have to rewrite all my Code.

PHP 服务器将一直运行,因为正常"页面基于它.但是加载和保存应该由NodeJS Server来管理.

The PHP Server will alwasy be running, because the "normal" Page is based on it. But loading and saving should be managed by the NodeJS Server.

推荐答案

您可以为此使用 node.js request 库 -示例在 - https://github.com/request/request

You may use node.js request library for this - Examples are provided in - https://github.com/request/request

您的客户端ajax代码应该指向node.js应用程序服务器,然后从node.js服务器,您可以通过上面的代码和回调发送请求,您将得到结果,您可以将其作为响应返回到您的 ajax 回调...

Your client side ajax code should direct to node.js application server and then from node.js server, you can send request through the above and on callback of the code,you will have the result, which you can return as response to your ajax callback...

希望对您有所帮助.

这篇关于从 NodeJS 调用 PHP 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆