在自己頁(yè)面顯示其他網(wǎng)站上面的數(shù)據(jù),需要用ajax,就涉及到跨域問(wèn)題,
解決方案:jquery.support.cors = true; (瀏覽器支持跨域訪問(wèn)),
實(shí)例:
代碼如下:
//瀏覽器支持跨域訪問(wèn)
jquery.support.cors = true;
$.ajax({
url: http://www.rj99999.com/price/listprice.html,
datatype: 'html',
success: function (data, textstatus) {
//nowprice為本頁(yè)面顯示數(shù)據(jù)控件,#price', data為從其他網(wǎng)站取出名為price的元素。
$(#nowprice).text(jquery('#price', data).html() + 元/克);
},
error: function (xhr, ajaxoptions, thrownerror) {
$(#nowprice).text(暫時(shí)無(wú)法顯示);
}
});
//實(shí)時(shí)刷新
//每60000毫秒/1分鐘調(diào)用togglecountdowntime()方法。
settimeout(togglecountdowntime(), 60000);
更多信息請(qǐng)查看IT技術(shù)專欄