Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax driven site #175

Closed
pjam opened this issue Jul 15, 2015 · 4 comments
Closed

Ajax driven site #175

pjam opened this issue Jul 15, 2015 · 4 comments

Comments

@pjam
Copy link
Contributor

pjam commented Jul 15, 2015

Hi.

I'm developing an app with s2a that needs to use websockets. Because of that, I want to avoid page reloads to keep from disconnecting and connecting the socket (done in js) for every page visited.

So I am thinking of "ajaxifying" the app, but I'm not being able to do that.
Can you point me at the easiest way to do this? Or any other approach that I'm not seeing?

@bobvandevijver
Copy link
Member

Hi there,

I think I must disappoint you: With my own experience with Websockets, I do not think that the current bundle can be used with the setup you have in mind. Or at least, not without significantly rewriting the templates. This is mostly because of the Twig template oriented style: everything is rendering in a twig template.

You would at least need to redefine all (or add more) controllers to enable JSON data export. And you would need to write your own JS logic on the page to refresh all data, and then I am not yet considering adding new rows.

There is already an issue about AJAX capabilities, see #59. However, AJAX and websockets are two completely different things, so you should consider both I guess.

@pjam
Copy link
Contributor Author

pjam commented Jul 16, 2015

Hi @bobvandevijver

Allow me to disagree as I got it to work. Since every request return something with a base template (I use the one provided by the bundle), I wrapped everything that I don't want to be reloaded in the base_uncompressed.html.twig file with {% if not app.request.isXmlHttpRequest() %}{% endif %} and made every link trigger an ajax call that loads in the main aside section.

I still haven't finished turning the forms into ajax forms with the ajaxForm plugin, but for everything seems to be working except the collapse/expand filters button.

All javascript files get loaded only once, including the one where I make the socket connection, as I wanted.

Now I just need to solve the filter button problem.

@pjam
Copy link
Contributor Author

pjam commented Aug 7, 2015

Well, I got this to work as I wanted, so you can close the issue if you wish.

If anyone needs help with this, just contact me.

@bobvandevijver
Copy link
Member

I do not like the app.request.isXmlHttpRequest() method to check if the request is indeed an AJAX call, but for most cases it should work just fine.

To clarify why I think it is not the best method:
"Symfony\Component\HttpFoundation\Request::isXmlHttpRequest() is a simply utility-method that checks whether HTTP request came up with X-Requested-With header with value XMLHttpRequest. So it's as reliable as X-Requested-With header is."
Source: Stackoverflow

I will close this, as it is not an issue for the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants