Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess html content loaded with jQuery's load() function
    primarykey
    data
    text
    <p>I'm a bit confused by how jQuery ajax works. I'm trying to create a customer management system (CMS) with jQuery and php.</p> <p>I want to give the user the opportunity to create a car. Let's say he must define a "car name" and check some options in a checkbox list. At the same page i give the user the opportunity to add or delete some options. This adding and deleting happens with jQuery and ajax. When a user add an option, i call a php page (addOption.php) that processes the option and add's it to the database. If the ajax call is successful, i reload the options in a div using the ajax load() function. Who calls a php page (reloadOptions.php) that reads out the options from the database and constructs them into a list of check-boxes.</p> <p>All this works fine. The problem occurs when i try to check what check-boxes are checked. (difficult sentence here ) It seems that the data don't exist in the page source. I think this happens because of the asynchronous working of ajax. And i really need the options to create the car!</p> <p>Finally, my question is how can i access that options data? And if you can't, is there still a way where you can access that data? What do you think about my approach to handle the cms system? Good / Bad / omg / ...</p> <p>Below are some code blocks i use:</p> <p>The page index.php : jQuery/ajax that processes the options and the html code</p> <pre><code> //At the start i load the options in $('.options').load('./php/OptionsReload.php'); $("#FormOptions").submit(function(e) { $.ajax({ type: "POST", url: "./php/addOption.php", data: $(e.target).serialize(), dataType: "json", success: function(data) { $('.options').load('./php/reloadOptions.php'); } }); return false; }); .................. //Form where you can add the option &lt;form id="FormOptions"&gt; &lt;input type="text" name="optionName" /&gt; &lt;input type="submit" name="submitOption" value="Add option" /&gt; &lt;/form&gt; ...................... //Div where i show the options to the user &lt;form name="formChecks" method="post" enctype="multipart/form-data"&gt; &lt;div class="options"&gt; //Content loaded with jQuery &lt;/div&gt; &lt;/form&gt; </code></pre> <p>The page addOption.php : code that adds the option to the database</p> <pre><code> //Database connect ... return mysql_query("INSERT INTO options(option) VALUES('". $POST_['optionName'] ."');"); </code></pre> <p>The page reloadOptions.php : code that constructs the html with the options </p> <pre><code>&lt;select name="mydropdown"&gt; &lt;?php $options = ...... connect with DB and select all the options while($row = mysql_fetch_assoc($options)) { echo ("&lt;option value='" . $row['Id'] . "'&gt;" . $row['optionName'] . "&lt;/option&gt;"); } ?&gt; &lt;/select&gt; </code></pre> <p>Thanks in advance, Bert</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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