Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax loading for complex projects
    text
    copied!<p>My problem is actually not the ajax loading itself, more the capability to load it without javascript. I mean, I cope easily when I code my whole project <em>just</em> based on ajax-availability <strong>OR</strong> <em>just</em> without the use of ajax.</p> <p><strong>//EDIT: Although Arend already had a more or less valid answer, at the same time 'there is no direct answer to this question'. However, I'd like to see some other approaches of developers for scenarios like mine though! Even just a few links can help!</strong></p> <p>Basically I just get frustrated, coding everything twice on the same page to make sure that both users without and with Javascript enabled have the same experience. It's annoying and I was always wondering how others solve this problem.</p> <p>When I update for example two divs with dependency on the same variables, it gets messy. Here's an example:</p> <p><strong>non-js-version</strong></p> <pre><code>require 'classobject.class.php'; $another_var = 'something'; $class = new classobject($_POST['variable']); // just an example to show that this is dynamic - I'm aware of injection! $function = $class-&gt;returnsth(); // returns 1 if(isset($_POST)) { echo '&lt;div id="one"&gt;Module 1 says:'; $require 'module_one.php'; echo '&lt;/div&gt;'; echo '&lt;br /&gt;&lt;br /&gt;'; echo '&lt;div id="two"&gt;Module 2 says:'; $require 'module_two.php'; echo '&lt;/div&gt;'; } </code></pre> <p>Now in <code>module_two.php</code> and <code>module_two.php</code> I have code that executes differently depending on the return variable of $function. Like:</p> <pre><code>if($function &gt;= 1 &amp;&amp; another_var != 'something') { // do stuff } else { // do other stuff } </code></pre> <p>Now as this works easily with a reload, when I want to load the two modules on keyUp/enter/submit or whatever, I have basically a few problems:</p> <ul> <li>I have to send the <code>$_POST</code> variables manually to the modules to use them</li> <li>I have to re-execute the class &amp; it's methods and make a link (require_once) to them in each of the module-files.</li> <li>As $another_var is not existent in the modules, I'd have to send this variable to each modules, too (with post for example) and then before it can be used, I'd have to 'change' it like <code>$another_var = $_POST['another_var'];</code></li> </ul> <p>I find this mildly annoying and I wonder how you guys do that. I hope my way of coding is not too silly, but I can't think of another way. It's probably hard to relate to my very basic example, but to bring a whole project with the code would be too much. <strong>To sum it up, I'm looking for a better way to code and clean this mess up - there must be a way!</strong> I thought about sessions, but for compatability I don't want to rely on them either (if someone doesn't allow cookies).</p> <p>In case you can't relate to what I'm trying to accomplish with that way of having my code assembled, I'll explain a scenario I'm facing quite a lot (<strong>not important if you already understand my misery</strong>):</p> <ol> <li>Basically I have my <code>index.php</code> page where everything gets executed, with the html body and css styling and so on. This page expects some variables, that get set from the page that requires the index (like <code>$another_var</code> in my example). </li> <li>Now other variables can get set too (from a form for example). Depending on that different classes and methods load new variables (arrays) that get used in while-loops in my modules to echo everything out. </li> </ol> <p>Hope that's not too abstract. Think of a booking system where some variables are set from the page you are coming from (the event you want to book) and then a few more things get set by the user (a timespan, some preferences,...). In the end it's supposed to show results from the database all the way to the end-result - you can say the user narrows the results from step to step.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload