i using php curl make http long polling request javascript using ajax. here call javascript
var i; i++; $.ajax({ url:"http://localhost/myport.php", type: get, success: function(response){ ...}, ... ... here how make php call in myport.php file
<?php $ch=curl_init(); $curl_setopt($ch, curlopt_url, "http://localhost:7555/test?index=" //here need set value (the variable i) in above js if making call directly js, do
$.ajax({ url:"http://localhost:7555/test?index=" + i new php , curl, wondering how can pass value of variable can parameter call.
if understand correctly, , want append value of variable $i curl call, you'd this:
<?php $ch=curl_init(); curl_setopt($ch, curlopt_url, "http://localhost:7555/test?index=" . $i); or even,
curl_setopt($ch, curlopt_url, sprintf("http://localhost:7555/test?index=%d", $i)); also note hat there no $ before function call: it's curl_setopt() not $curl_setopt() ($ variables, $ch).
edit
upon clarification of question, seems need i variable javascript php. can pass get parameter in ajax call:
var i; i++; $.ajax({ url:"http://localhost/myport.php?index=" + i, type: get, success: function(response){ ...}, ... ... then, php, can use this:
curl_setopt($ch, curlopt_url, sprintf("http://localhost:7555/test?index=%d", $_get['index'])); you should verify $_get['index'] passed in:
if (!isset($_get['index'])) { die("the index not specified!"); }
Comments
Post a Comment