$(function?()?{
??$("img[id^='isshow']").click(function()?{
????var?$id?=?$(this).attr('id').replace('isshow',?'');
????if?($(this).attr('src').match('yes'))?{
??????var?$isshow?=?'yes';
??????var?$newisshow?=?'no';
????}?else?{
??????var?$isshow?=?'no';
??????var?$newisshow?=?'yes';
????}
????var?$data?=?0;
????$.ajax({
??????type:?'post',
??????url:?'__URL__/isshowPro',
??????//?async?:?false,
??????data:?{'id':$id,?'isshow':$newisshow},
??????success:?function?(data)?{
????????$data?=?data;
??????}
????});
????if?($data?==?1)?{
??????$(this).attr('src',?function?()?{
??????????return?$(this).attr('src').replace($isshow,?$newisshow);
??????});
????}
??})??
})
如果?//?async?:?false?,?打開?,?火狐會出現(xiàn)這個警告?:
"主線程中同步的?XMLHttpRequest?已不推薦使用,因其對終端用戶的用戶體驗存在負(fù)面影響。更多幫助請見?http://xhr.spec.whatwg.org/"
問?:?如果?async?:?true?,?如何同步地實現(xiàn)這段代碼??
if?($data?==?1)?{
??????$(this).attr('src',?function?()?{
??????????return?$(this).attr('src').replace($isshow,?$newisshow);
??????});
同步的 XMLHttpRequest 已不推薦使用 , 那怎么實現(xiàn)同步操作呢 ?
hhhzihao2
2016-05-16 17:03:45