Note that there are some explanatory texts on larger screens.

plurals
  1. POnginx comet long polling with jquery
    text
    copied!<p>Recently I have been trying to set up a comet server for my application on a Ngnix server using this plugin:<a href="https://github.com/wandenberg/nginx-push-stream-module" rel="nofollow">https://github.com/wandenberg/nginx-push-stream-module</a></p> <p>due to the restrictive nature of GNU/GPL I am unable to use the JS provided with the plugin, so I am trying to implement it on my own using jquery ajax requests.</p> <p>my Nginx config looks like this:</p> <pre><code> location /channels-stats { # activate channels statistics mode for this location push_stream_channels_statistics; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # query string based channel id set $push_stream_channel_id $arg_id; } location ~ /pub/(.*) { # activate publisher (admin) mode for this location push_stream_publisher admin; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # query string based channel id set $push_stream_channel_id $1; } location ~ /sub/(.*) { # activate subscriber (streaming) mode for this location push_stream_subscriber; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # positional channel path set $push_stream_channels_path $1; } </code></pre> <p>and the code snippets I am trying to use(in firebug) to test the both way communication is:</p> <pre><code>//reciever $.ajax({ url:'sub/test?callback=mycallback', dataType:'json', success:function(data){ console.log(data); } }); //sender $.ajax({ url:'pub/test', dataType:'json', type:'POST', data:'mycallback({"J":5,"0":"N"})' }); </code></pre> <p>I am trying to make it work cross domain, however I can not manage to get it to work even on the same domain, what acctualy happens is:</p> <p>when I use the recieving code, it initiates a connection to the server and is endlessly loading as it is supposed to be, and then I try to respond to the long poll with the sender code.</p> <p>now in the console on the NET tab(firebug) I can see that once I send the POST it recieves it in the response as plain text, but still maintains connection without giving a callback! so if i repeatedly send the post I can see in firebug in the net response tab that they are just collecting, but no callback is given from the reciever function! thus I am unable to acctualy extract the data!</p> <p>now I tried this both on another domain and in the same origin domain so I think the policy is not the problem here, what the problem is that the jquery snippet does not ever get to the callback, although it does reach the callback once the request timeouts ONLY! please help.</p> <p>on a side note, if you think there is an alternative plugin for NGINX which would suit me better please let me know.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload