0

So I've given RequireJS a try this weekend, and although it appears to work pretty smooth, I can't figure out one thing: How do I combine PHP and Javascript while using RequireJS?

See, RequireJS can only work with .js files, meaning that it cannot "require" .php files. In many files, however, I use PHP to retrieve database data which is then used by Javascript. It feels pretty inefficient to me to take apart these processes and let my Javascript execute an AJAX request to retrieve the settings I can normally set with PHP directly. Is there anyone with experience with this that maybe knows a solution or a way how to deal with this?

3
Contributors
4
Replies
11
Views
2 Years
Discussion Span
Last Post by minitauros
0

It feels pretty inefficient to me to take apart these processes and let my Javascript execute an AJAX request to retrieve the settings

That's the normal flow of things. RequireJS is used to load Javascript modules. There's no way to include PHP on the client-side, or to let Javascript connect to your database.

0

Yeah, I thought so.. Too bad, I think I'm just gonna stick with what I have for now, then. I had hoped for a way to let RequireJS "require" a .php file, which would actually be Javascript but with some PHP in it. Thanks for your answer!

Edited by minitauros

0

Depending on your situation, you could use AngularJS.

Okay it's not perfect, but it is backed by the Google development team and is an extremely efficient way of combining client+server side code. It doesn't 'require' PHP as such, but pretty much the same thing. It would be able to do the same thing when handling your 'settings'.

Personally I think it's pretty cool, and there's an example of a simple SQL query with PHP on this page.

0

I have heard of AngularJS, but I've never really looked into it. Does seem interesting, thanks for the tip!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.