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

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

问题描述

我有一个工作的基于PHP的API,它发送的JSON数据的Ajax请求。

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

我不知道是否有什么办法可以从NodeJS调用这些PHP文件,甚至通过一个Ajax请求,所以我不必重写所有我的code。

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服务器将alwasy运行,因为正常的页面是基于它。 但是,加载和保存应由NodeJS服务器进行管理。

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的请求库本 - https://github.com/request/request

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

您的客户端AJAX code应该直接到的Node.js应用程序服务器,然后从服务器的nod​​e.js,就可以通过的code以上,并在回调发送请求时,你就会有结果,您可以返回为响应您的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天全站免登陆