简体   繁体   English

使用php文件从端口80重定向到另一个端口

[英]Using a php file to redirect from port 80 to another port

I need to make a http call from Javascript to my web client which is port 7043. So I m making a php call that will redirect my call. 我需要从Javascript到端口7043的Web客户端进行http调用。因此,我正在进行php调用,它将重定向我的调用。 My php and javascript files are in the root directory of apache and my javascript is making the call to the php file ( http://localhost/redirect.php ) and this is what I am doing in the php file 我的php和javascript文件位于apache的根目录中,而我的javascript正在调用php文件( http://localhost/redirect.php ),这就是我在php文件中所做的工作

$file = fsockopen("localhost:7043/test/testclient.json", 7043)

This does seem to only open the initial "It works!" 这似乎只打开了初始的“行得通”! web page that comes with apache. apache附带的网页。 the testclient.json returns a json response (which I parse in Javascript) could this be the problem? testclient.json返回一个json响应(我用Javascript解析)可能是问题所在吗? what do I need to do in php? 我需要在php中做什么?

Using jQuery: 使用jQuery:

You have to write only: 您只需要写:

$.getJSON("http://localhost:7043/test/testclient.json?callback=jp", function(jsonRecieved){
  // jsonReceived is a var that contains your testclient.json already parsed by jQuery
  // so, do what you want with it here
});


In your html body , put somewhere (before </body> for example) 在您的html正文中 ,放置某处(例如</body>之前)

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

You can download jQuery and see more at https://jquery.com/ 您可以下载jQuery并在https://jquery.com/上查看更多内容。
See some $.getJSON examples . 请参阅一些$ .getJSON示例
More about Cross-Origin Resource Sharing (CORS) . 有关跨域资源共享(CORS)的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM