靜態頁面 寫ajax擷取介面 載入資料案例
最後更新:2018-07-29
來源:互聯網
上載者:User
<script language="javascript">
init();
function init(){
var shareConfId = GetQueryString('share_config_id');
shareConfId=3081;
loadShareConfid(shareConfId);
loadTemplate(shareConfId);
}
//載入分享配置
function loadShareConfid(shareConfId){
$.ajax({
url: "http://localhost:8096/shareConfInfo/"+shareConfId,
type:"GET",
async:false,
data:{},
dataType:"jsonp",
jsonp:"callbackparam",
jsonpCallback:"callbackparam",
success:function(data)
{
$('#t_title').html(data.title);
}
});
}
function loadTemplate(shareConfId){
$.ajax({
url: "http://localhost:8096/templateInfo/"+shareConfId,
type:"GET",
async:false,
data:{},
dataType:"jsonp",
jsonp:"callbackparam",
jsonpCallback:"callbackparam",
success:function(data)
{
$('#head_img').attr('src',data.shareHeadImg);
$('#activity_img').attr('src',data.shareActivityDesImg);
if(data.shareLiveBtn == null || data.shareLiveBtn == '' ){
$('#a_btn3').show();
$('#div_img3').attr('src',data.downBtnImg);
$('#a_btn3').attr('href',"http://www.shihoutv.com/app");
}else{
$('#div_btn').show();
$('#div_img1').attr('src',data.downBtnImg);
$('#div_img2').attr('src',data.shareLiveBtn);
$('#a_btn1').attr('href',"http://www.shihoutv.com/app");
$('#a_btn2').attr('href',"http://m.shihou.tv/redirect_room?room_id="+data.shareLiveRoomId);
}
}
});
}
//擷取地址欄參數
function GetQueryString(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
</script>