使用bootstrapTable獲取數(shù)據(jù)時(shí),有時(shí)由于網(wǎng)絡(luò)或者服務(wù)器的原因,無法及時(shí)獲取到數(shù)據(jù),頁(yè)面顯示一直處于等待狀態(tài)。為了改善效果,考慮設(shè)置超時(shí),請(qǐng)求發(fā)送后超時(shí)即顯示無數(shù)據(jù),過段時(shí)間重新發(fā)起請(qǐng)求。
實(shí)現(xiàn)上,bootstrapTable通過ajax獲取數(shù)據(jù),可以使用ajaxOptions選項(xiàng)設(shè)置ajax的一些屬性。
bootstrapTable要設(shè)置timeout,首先要將async屬性設(shè)置為true,在bootstrapTable中async默認(rèn)是false的。例如
$("#event_table").bootstrapTable({ url: urlAddr, ajaxOptions: {async:true,timeout:5000},});另外,使用refresh方法加ajaxOptions,卻沒有作用:
$(“#event_table”).bootstrapTable('refresh', { url: api_url, ajaxOptions:{async:true,timeout:1000}});原因有待進(jìn)一步深究。
下面看下在使用bootstrapTable獲取數(shù)據(jù)時(shí),如何獲悉table數(shù)據(jù)是否加載成功?
bootstrapTable提供了專門的loadsuccess方法,用于反映數(shù)據(jù)是否加載成功。
$table.on('load-success.bs.table',function(data){ console.log("load success"); });bootstrapTable使用文檔,可參考http://bootstrap-table.wenzhixin.net.cn/documentation/
參考:
boostrapTable的refresh和refreshOptions區(qū)別淺析
以上所述是小編給大家介紹的BootstrapTable請(qǐng)求數(shù)據(jù)時(shí)設(shè)置超時(shí)(timeout)的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注