我一直在尝试使用 ajax 从灯箱将数据发布回控制器,但它当然不起作用。
我有两个选择列表,都从默认控制器填充。当我选择一个值并单击提交时,我的错误框会短暂闪烁,然后再次消失。
使用萤火虫网络选项卡我可以看到 POST 请求,但是在 post 选项卡下没有数据。我必须在 javascript 本身中做错了什么,但对我来说它看起来不错,而且我所有的谷歌搜索都没有提出可行的替代方案。
这是我的代码...
<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 your preferred Currancy</i></option>
<?php foreach($currencies as $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 your preferred Language</option>
<?php foreach($languages as $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 your preferred Language</option>
<?php foreach($regions as $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>
当错误通知将就绪状态和状态都标记为 0 时, throwederror 就是错误。
此外,接收控制器目前只是一个 print_r(&_POST) 来测试。
我自己似乎无法克服这一点,如果有人可以提供帮助,我们将不胜感激。
谢谢