php - No POST data in jquery ajax call -
i've been trying post data controller lightbox using ajax of course doesn't work.
i have 2 select lists, both populated default controller. when select value , click submit have error box briefly flash disappear again.
using firebug network tab can see post request under post tab there's no data. must doing wrong in javascript me looks ok , googling didn't suggest alternative worked.
here's code...
<body style="background-color: #f0f0f0;"> <div style="margin: 5px;"> <div id="ajax-login-register"> <div id="login-box"> <div style="text-align: center; font-weight: bold; font-size: 20px; margin: 10px 0 20px 0; border-bottom: #ccc 2px dashed; padding-bottom: 12px;"><?=lang('login')?></div> <form id="login-form"> <select name="currency_sel" id="brand_country" class="form_select_200px"> <option value="0" selected><i>select preferred currancy</i></option> <?php foreach($currencies $currency): ?> <option value="<?php echo $currency['currency_id']; ?>"><?php echo $currency['currency_name']; ?></option> <?php endforeach; ?> </select> </form> </div> <div id="register-box"> <div style="text-align: center; font-weight: bold; font-size: 20px; margin: 10px 0 20px 0; border-bottom: #ccc 2px dashed; padding-bottom: 12px;"><?=lang('meta_description')?></div> <form id="register-form"> <select name="language_sel_1" id="brand_country" class="form_select_200px"> <option value="0" selected>select preferred language</option> <?php foreach($languages $language): ?> <option value="<?php echo $language['language_id']; ?>"><?php echo $language['language_name']; ?></option> <?php endforeach; ?> </select> <select name="language_sel_2" id="brand_country" class="form_select_200px"> <option value="0" selected>select preferred language</option> <?php foreach($regions $region): ?> <option value="<?php echo $region['country_id']; ?>"><?php echo $region['country_name']; ?></option> <?php endforeach; ?> </select> <div class="line"> </div> </form> </div> <div> <form> <button id="ajax-submit-button" style="font-size: 14px;"><?//=lang('register')?>submit</button> </form> </div> </div> </div> <script type="text/javascript"> $(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: "<?=site_url('locale/set_ui_lang')?>", 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); } }); } }); }); </script> </body>
when error notice flags ready state , status both come 0, thrownerror error.
also receiving controller print_r(&_post) test.
i don't seem able past myself, if can appreciated.
thanks
the keys of data object should not in quotes.
it should work (provided jquery calls values work) when change to:
data: { currency_sel: $('#currency_sel :selected').val(), language_sel_1: $('#language_sel_1 :selected').val(), language_sel_2: $('#language_sel_2 :selected').val() },
source: jquery.ajax() documentation
Comments
Post a Comment