Long polling or ajax?


I have to make http api calls to another server that doesnt use websockets. I was thinking of using long polling for it to get the data but havent seen any documentation about it? right now, im using ajax to make the request. just wondering if there is a better way to do it in phoenix.


Ajax is the client side.

Do you need to make the call from phoenix server? If so I would use an available http client like httpoison.

I make the call from phoenix but I wanted it to do long polling to check the server every x amount of time so was using ajax on the js file inside of phoenix but then got stuck because of cors stuff even after installing the cors plugin. :confused: can i do long polling with httppoison?

thanks :slight_smile:

You can use a timer, or Process.send_after.

If it was me, I would span a genserver, that will fire an event each x amount of time.


thanks! will try to create a genserver with httppoison + timer/Process.send_after. :slight_smile:

still have a lot to learn.

Have a look at this post Scheduled function - Task or Agent?

There is some sample code, plus some good comments related (Not the httpoison part)

1 Like

thanks will check it out :slight_smile: need me some more elixir :stuck_out_tongue:

1 Like