Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to deal with JSON results in JQuery using $.Ajax
    text
    copied!<p>I have a FORM with three elements; a text field, and two select dropdown elements:</p> <pre><code>&lt;input type="text" name="UserCode" id="UserCode"&gt; &lt;select name="OrderCode" id="OrderCode"&gt;&lt;/select&gt; &lt;select name="RegionCode" id="RegionCode"&gt;&lt;/select&gt; </code></pre> <p>When the text in the <code>UserCode</code> field is changed, I am tying to use JQuery to fire off a request to get some data about that User. The data is returned in JSON format. Here is what the JSON data looks like (copied from Firebug console):</p> <pre><code>{ "COLUMNS":["ORDERTITLE","ORDERCODE"], "DATA":[ ["Marketing","00000381"],["Fashion and Textile Buying Management","00006058"] ] } </code></pre> <p>The JQuery code that allows the above to happen is this (so far):</p> <pre><code>$(function() { $('#UserCode').blur(function() { $.ajax({ type: 'get', url: '/_assets/cfc/orders/order-dbqueries.cfc', data: {method:'account_customer_Orders', UserCode:$(this).val()}, dataType: 'json', success: function(result){ //NO IDEA WHAT TO DO HERE TO GET THE JSON DATA INTO THE #ORDERCODE SELECT FORM ELEMENT } }); }); }); </code></pre> <p>I have some questions:</p> <ol> <li>How do I get the JSON data returned to populate the #OrderCode select element with attributes like such: <code>&lt;option value="OrderCode"&gt; OrderTitle &lt;/option&gt;</code></li> <li>If question 1 can be resolved successfully, then the next step is that my URL needs to return more than one result set in order to populate the other element with ID #RegionCode. How can the JQuery code handle two JSON returns if that's even possible?</li> </ol>
 

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