1
我有一个选择菜单,触发ajax帖子,然后显示成功或失败消息:成功。选择菜单重置为以前选择的选项
为菜单中的HTML看起来像这样:
<select name="return_action_id" class="form-control">
<option value="0"> --- Please Select --- </option>
<option value="1" selected>Refunded</option>
<option value="2">Credit Issued</option>
<option value="3">Replacement Sent</option>
</select>
的JavaScript的AJAX后看起来像这样:
$('select[name="return_action_id"]').change(function(){
var a=$(this);
var value = a.val();
$.ajax({
url:'index.php?route=sale/returns/action&token=<?= $token; ?>&return_id=<?= $return_id; ?>',
type:'post',
dataType:'json',
data:'return_action_id='+value,
beforeSend:function(){
a.blur().button('loading').append($('<i>',{class:'icon-loading'}));
},
complete:function(){
a.button('reset');
},
success:function(json){
if(json['error']){
alertMessage('danger',json['error']);
}
if(json['success']){
alertMessage('success',json['success']);
//$('select[name="return_action_id"] option:selected').prop('selected', false);
//$('select[name="return_action_id"] option[value="'+value+'"]').prop('selected', true);
}
}
});
});
每次我从菜单中选择一个选项,阿贾克斯火灾并按预期创建我的消息,但所选选项未收到所选属性,并且菜单将恢复为最初选定的选项。
例如在上面的html代码中,当前选择了Refunded。如果我在菜单中选择信用卡,则Ajax将触发,菜单将恢复为已选择退款。
你会在javascript成功的方法中看到我有一些代码注释掉了我试图让它表现的地方。
任何帮助,将不胜感激。
您在此处重置'select'菜单'a.button('reset');'? – adricadar 2015-04-03 06:25:52
没错,就是这样,这就是我得到的回收代码。谢谢一堆。如果您将此作为答案提交,我会接受它。 – 2015-04-03 06:57:19
我暗示了答案:),我很高兴我帮助你:D。 – adricadar 2015-04-03 10:05:40