ajax,jsonp调取信息方式:
$(function(){
// $("#t310").prepend(classCourse(310))
})
/* 课程 */
// http://bj.xdf.cn/school/categoryClassjsonp?categoryCode=186&one=310&size=4&count=4
function classCourse(id_,id,dom,cout){
$.ajax({
type:'get',
url:"http://bj.xdf.cn/school/categoryClassjsonp?categoryCode="+id_+"&one="+id+"&size="+cout,
dataType:"jsonp",
jsonp: "callback",
// jsonpCallback:"soukecourse",
success:function(data){
// console.log(data)
var classCode=data;
var detail='';
var now_date=new Date().Format("yyyy-MM-dd");;
now_p_date=parseInt(now_date.replace(/-/g,''),10);
for(var i=0;i<classCode.length;i++){
if(parseInt(classCode[i].startdate.substr(0,10).replace(/-/g,''),10)<now_p_date){
continue;
}
detail+='<tr><td>'+classCode[i].classname+'</td><td>'+classCode[i].startdate.substr(0,10)+'</td><td>'+classCode[i].classtimes+'次课'+'</td><td>'+classCode[i].price+'元</td><td class="boder-r"><a href="'+classCode[i].soukeline+'" target="_blank">免费了解课程</a></td></tr>'
}
if(detail!==''){
// $('.kc-cont').find('tbody:first').prepend(detail);
$("#"+dom).prepend(detail)
}
// console.log(detail)
// return detail;
},error:function(){
alert("网络异常")
}
})
}
classCourse(186,310,'t310',4);
classCourse(186,325,'t325',6);
classCourse(186,326,'t326',5);
classCourse(186,327,'t327',5);
classCourse(186,328,'t328',5);
classCourse(186,318,'t318',4);
classCourse(186,315,'t315',4);
classCourse(186,316,'t316',4);
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"H+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
// 校区信息调取
function schoolAdress(){
$.ajax({
type:'get',
url:'http://bj.xdf.cn/school/yasixuexi.html',
dataType:'jsonp',
jsonp:'callback',
success:function(data){
var address=data.schoolMap;
// console.log(data)
var deta1='';
for(attr in address){
for(var i=0;i<address[attr].length;i++){
// console.log(address[attr][i].school_name)
deta1+='<li><span>'+address[attr][i].school_name+'</span><p><a href="http://bj.xdf.cn/school/schoolDetail_'+address[attr][i].school_id+'" target="_blank">'+address[attr][i].school_address+'</a></p></li>';
}
}
// console.log(obj,obj2)
if(deta1!==''){
$('.ul_lef').prepend(deta1)
}
}
})
}
schoolAdress();
使用轮播插件调取信息时注意,插件的加载顺序,否则插件的功能不可用,在success函数中调取成功之后再加载插件
<script src="http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
type:'get',
url:"http://new.bj.xdf.cn/teacher/index.php?s=/api/index/getTjTeacher/part/2/num/8",
dataType:"jsonp",
jsonp: "callback",
success:function(data){
var item='';
var datademo=data;
// console.log(datademo);
for(var i=0;i<datademo.length;i++){
item+='<div class="item"><img src="http://new.bj.xdf.cn/teacher/'+datademo[i].big_img+'" alt=""><div class="detail"><p class="p1">'+datademo[i].teachername
+'</p><p class="p2">教授课程:'+datademo[i].souke_course+'</p><p class="p3">毕业院校:'+datademo[i].experience+'</p></div></div>'
}
if(item!==''){
$('#owl-demo').prepend(item);
showd();
}
}
})
function showd(){
$("#owl-demo").owlCarousel({
items: 4,
loop: true,
});
}
})
</script>
<script src="js/owl.carousel.js"></script>