I am curious how best to use PHP in an AJAX setting. A lot of websites use AJAX to make it feel as if you are still on the same page, like in single-page web applications, and sending POST data to a php file on the server that generates data that is returned back to JavaScript context. I believe this is how RESTful APIs work.
What is the best way to do this in Haxe-generated php code?
Since Haxe generates an index.php
file which sets up the environment then calls Main::main()
, the POST data by that point is no longer valid as PHP is stateless (it doesnât share the POST data with other PHP files), and there doesnât seem to be a way to pass that onto the Main constructor call through which you can handle such requests.
Does the Haxe PHP target only work if you only use it to generate HTML5 pages, or is it indeed possible to use it with AJAX in JavaScript context? The only workarounds I have found are very insecure, which either involves using Cookies (which I would rather avoid) or sessions. Is there any other way I can use the Haxe PHP target for AJAX calls? Is it possible, perhaps, to generate PHP code that is procedural and not object-oriented where these problems no longer arise?