Jon*_*Suh 11 javascript php ajax curl
我正在关注使用HTTP长轮询的Spring MVC聊天客户端的这个例子.
我的Web服务器位于端口7555,我需要能够从端口80(浏览器)向端口7555发出HTTP长轮询请求,因此我创建了一个调用我的webservice的PHP脚本.
<?php
$index = $_GET["index"];
echo $index;
echo $index2;
$urlVar = "http://localhost:7555/test?" . $index . $index2;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlVar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PORT, 7305);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_exec($ch)
?>
Run Code Online (Sandbox Code Playgroud)
我用我的JavaScript调用这个PHP文件,参数如下:
($.ajax({
url : "http://localhost/myphpscript.php?index=" + i,
type : "GET",
cache: false,
success : function(messages) {
//do stuff
}
}));
Run Code Online (Sandbox Code Playgroud)
PHP文件位于我的localhost中.这似乎不起作用,因为JavaScript似乎无休止地调用PHP(它调用URL).我是否正确使用PHP curl进行长时间轮询?我是否需要在JavaScript中进行Ajax调用,因为我是curl中的HTTP调用?