Javascript 使用curl命令的Ajax长轮询

Javascript 使用curl命令的Ajax长轮询,javascript,php,ajax,spring,curl,Javascript,Php,Ajax,Spring,Curl,我的本地主机上有我的文件,我正试图向我的web服务器发出HTTP长轮询请求,该服务器位于localhost:7305中。由于浏览器使用端口80进行调用,因此我得到了错误消息 XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin. No "Access Control Allow Origin" header is present on the request resource. GET

我的本地主机上有我的文件,我正试图向我的web服务器发出HTTP长轮询请求,该服务器位于localhost:7305中。由于浏览器使用端口80进行调用,因此我得到了错误消息

XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin. No "Access Control Allow Origin" header is present on the request resource.
 GET http://localhost/bypass.php 500 (Internal Server Error)
 f.support.ajax.f.ajaxTransport.send
 f.extend.ajax
 longpoll
因此,我设计了一个带有curl的php代码来进行调用:

 <?php
 error_reporting(E_ALL);
 ini_set('display_errors', '1');

 $ch = curl_init();

 curl_setopt($ch, CURLOPT_URL, "http://localhost:7555/test?list=0");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_PORT, 7555);

 curl_setopt($ch, CURLOPT_TIMEOUT, 10);

 $out = curl_exec($ch);

 curl_close($ch);

 echo $out;

 ?>
它应该返回字符串列表,但我得到了错误

XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin. No "Access Control Allow Origin" header is present on the request resource.
 GET http://localhost/bypass.php 500 (Internal Server Error)
 f.support.ajax.f.ajaxTransport.send
 f.extend.ajax
 longpoll

我不确定是什么原因造成的?可能是因为ajax正在进行异步调用吗?web服务器处于spring中,并返回一个DeferredResult对象。感谢您的帮助

500错误几乎总是由服务器端代码引起的。您现在需要调试服务器端代码,看看它为什么返回500。为什么您可以正确地实现CORS并跳过中间人请求,而使用php从您的本地Web服务器请求?@KevinB如果我将javascript代码放在tomcat中,并在与服务相同的端口中运行,它不会出现任何问题,它会根据需要工作。所以我没有看到任何服务器端issue@KevinB我不知道如何实施CORS?我怎么能这样做?例如,帮助取决于Web服务器使用的语言。如果您使用该特定语言搜索CORS,您将得到大量示例。500错误几乎总是由服务器端代码引起的。您现在需要调试服务器端代码,看看它为什么返回500。为什么您可以正确地实现CORS并跳过中间人请求,而使用php从您的本地Web服务器请求?@KevinB如果我将javascript代码放在tomcat中,并在与服务相同的端口中运行,它不会出现任何问题,它会根据需要工作。所以我没有看到任何服务器端issue@KevinB我不知道如何实施CORS?我怎么能这样做?例如,帮助取决于Web服务器使用的语言。如果你用这种特定的语言搜索CORS,你会得到大量的例子。