ajax each html 太多,HTML5学习小记二ajax,window.orientation,prototype.forEach

1.ajax的学习

HTML5中的ajax相当于iOS中的afnetworking;详见jQuery ajax - ajax() 方法;

对ajax使用post请求的demo练习:

function testPost(){

$.ajax({

type:"POST",//请求的类型 POST GET 无大小写区分

url:"http://www.test.com",

data:{name:"post",phone:"3112122"},//post请求的追加参数,与iOS中的字典相同;

datatype: "html",//返回数据的格式"xml", "html", "script", "json", "jsonp", "text".

beforeSend:function(){$("#msg").html("logining");},//请求之前调用的函数

success:function(data){  //请求成功返回调用的函数

$("#msg").html(decodeURI(data));

}  ,

//调用执行后调用的函数

complete: function(XMLHttpRequest, textStatus){

alert(XMLHttpRequest.responseText);

alert(textStatus);

//HideLoading();},

success :function(data){

//请求成功的处理方法

}

error: function(){

//请求出错处理

}});}

对ajax的get请求的说明:

url的不同:    url = "update.php?username=" +encodeURIComponent(username) + "&content=" +encodeURIComponent(content)+"&id=1" ;

在ajax请求时 防止异步请求的方法

//var imgNum = $('img').length;

//$('img').load(function() {

//if (!--imgNum) {

//}

//});

2.获取到网页滑动的方法,当滑动到底部的时候进行加载下一页

$(window).scroll(function() {

var scrollTop = $(this).scrollTop();//方法返回或元素的滚动条的垂直位置。

var scrollHeight = $(document).height();//整篇文章的高度

var windowHeight = $(this).height();//是获取当前 也就是你浏览器所能看到的页面的那部分的高度  这个大小在你缩放浏览器窗口大小时 会改变 与document是不一样的  根据英文应该也能理解吧

if(scrollTop + windowHeight >= scrollHeight) {

orderid = $("#orderidHidden").val();

getdata(usertype, notvip, orderid);//执行的请求方法

}

});

3.  关于window.addeventlistener

当对一个对像绑定多个方法的时候,之后最后一个会生效,使用addeventlistener之后,每一个方法都是可以执行;用来解决让一个js事件执行多个函数

4.关于 window.orientation

window.addEventListener("onorientationchange" in window ? "orientationchange":"resize",function(){

if (window.orientation===180 ||window.orientation===0){

$('.lock_wrp').CSS("display","none");

console.log('这个是竖屏展示');}

if (window.orientation===90 ||window.orientation===-90){

$('.lock_wrp').css("display","block");

console.log('这个是横屏展示');

e.preventDefault();

});}});

屏幕旋转事件: onorientationchange   出自html5屏幕旋转事件 onorientationchange

function orientationChange() {

switch(window.orientation) {

case 0:

alert("肖像模式 0,screen-width: " + screen.width + "; screen-height:" + screen.height);            break;

case -90:

alert("左旋 -90,screen-width: " + screen.width + "; screen-height:" + screen.height);            break;

case 90:

alert("右旋 90,screen-width: " + screen.width + "; screen-height:" + screen.height);            break;

case 180:

alert("风景模式 180,screen-width: " + screen.width + "; screen-height:" + screen.height);          break;    };

};// 添加事件监听addEventListener('load', function(){    orientationChange();    window.onorientationchange = orientationChange;});

5.removeAttr() 方法从被选元素中移除属性。

if(!Array.prototype.forEach){

Array.prototype.forEach = function(callback,thisArg){

var T, k;

if(this === null){

throw new TypeError("this is null or not defined")

}

var O = Object(this);

var len = O.length >>> 0;

if(typeof callback !== "function"){

throw new TypeError(callback + " is not a function");

}

if(arguments.length > 1){

T = thisArg;

}

k = 0;

while(k < len){

var kValue;

if(k in O){

kValue = O[k];

callback.call(T,kValue,k,O);

}

k++;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值