Note that there are some explanatory texts on larger screens.

plurals
  1. PONo POST data in jquery ajax call
    primarykey
    data
    text
    <p>I've been trying to POST data back to a controller from a lightbox using ajax but of course it doesn't work. </p> <p>I have two select lists, both populated from the default controller. When I select a value and click the submit I have the error box briefly flash up the disappear again. </p> <p>Using the firebug network tab I can see the POST request however under the post tab there's no data. I must be doing something wrong in the javascript itself but to me it looks ok and all my googling didn't suggest an alternative that worked. </p> <p>Here's my code...</p> <pre><code>&lt;body style="background-color: #f0f0f0;"&gt; &lt;div style="margin: 5px;"&gt; &lt;div id="ajax-login-register"&gt; &lt;div id="login-box"&gt; &lt;div style="text-align: center; font-weight: bold; font-size: 20px; margin: 10px 0 20px 0; border-bottom: #ccc 2px dashed; padding-bottom: 12px;"&gt;&lt;?=lang('login')?&gt;&lt;/div&gt; &lt;form id="login-form"&gt; &lt;select name="currency_sel" id="brand_country" class="form_select_200px"&gt; &lt;option value="0" selected&gt;&lt;i&gt;Select your preferred Currancy&lt;/i&gt;&lt;/option&gt; &lt;?php foreach($currencies as $currency): ?&gt; &lt;option value="&lt;?php echo $currency['currency_id']; ?&gt;"&gt;&lt;?php echo $currency['currency_name']; ?&gt;&lt;/option&gt; &lt;?php endforeach; ?&gt; &lt;/select&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id="register-box"&gt; &lt;div style="text-align: center; font-weight: bold; font-size: 20px; margin: 10px 0 20px 0; border-bottom: #ccc 2px dashed; padding-bottom: 12px;"&gt;&lt;?=lang('meta_description')?&gt;&lt;/div&gt; &lt;form id="register-form"&gt; &lt;select name="language_sel_1" id="brand_country" class="form_select_200px"&gt; &lt;option value="0" selected&gt;Select your preferred Language&lt;/option&gt; &lt;?php foreach($languages as $language): ?&gt; &lt;option value="&lt;?php echo $language['language_id']; ?&gt;"&gt;&lt;?php echo $language['language_name']; ?&gt;&lt;/option&gt; &lt;?php endforeach; ?&gt; &lt;/select&gt; &lt;select name="language_sel_2" id="brand_country" class="form_select_200px"&gt; &lt;option value="0" selected&gt;Select your preferred Language&lt;/option&gt; &lt;?php foreach($regions as $region): ?&gt; &lt;option value="&lt;?php echo $region['country_id']; ?&gt;"&gt;&lt;?php echo $region['country_name']; ?&gt;&lt;/option&gt; &lt;?php endforeach; ?&gt; &lt;/select&gt; &lt;div class="line"&gt;&amp;nbsp;&lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;div&gt; &lt;form&gt; &lt;button id="ajax-submit-button" style="font-size: 14px;"&gt;&lt;?//=lang('register')?&gt;Submit&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#ajax-login-button').button({ icons: { primary: "ui-icon-check" } }); $('#ajax-submit-button').click(function(){ var error = false; if(error){ return false; } else { $.ajax({ url: "&lt;?=site_url('locale/set_ui_lang')?&gt;", type: "POST", dataType: "json", data: ({ 'currency_sel' : $('#currency_sel :selected').val(), 'language_sel_1' : $('#language_sel_1 :selected').val(), 'language_sel_2' : $('#language_sel_2 :selected').val() }), success: function(data){ parent.$.colorbox.close(); parent.location.reload(); }, error: function(xhr, ajaxOptions, thrownError){ alert("ERROR! \n\n readyState: " + xhr.readyState + "\n status: " + xhr.status + "\n thrownError: " + thrownError + "\n ajaxOptions: " + ajaxOptions); } }); } }); }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p>When the error notice flags up the ready state and status both come up 0, thrownerror is just error.</p> <p>Also the receiving controller is currently only just a print_r(&amp;_POST) to test.</p> <p>I don't seem to be able to get past this myself, if anyone can help it is much appreciated.</p> <p>Thanks</p>
    singulars
    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.
 

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