Admittedly, this probably doesn’t come up a lot for people, but recently I have been creating a project management system for someone and am trying to make it as user-friendly as possible using all my known tricks.
I want to use an Include function for PHP when a page loads, but this page doesn’t include functions because it's also called by jQuery and Ajax. So I simply just want to call this page and display the output.
Problem
The only problem is that I send it $_GET variables via the URL when I call it using jQuery. If I try the code below, it doesn’t work, because it is actually looking for a file with the exact name, and not clever enough to work out they are extra variables I am sending it.
Solution
To get around this, we only call the page name in the include statement, and we pre-set the $_GET arrays before.
Conclusion
Although this adds more code, it’s still fairly simple enough to use without it becoming a problem. Plus, it doesn’t look that messy either, and I like code that’s still readable.
I must thank Cory Gagliardi, who added a comment in the PHP documentation which allowed me to solve my problem after over an hour of tearing my hair out.