HTTP服务与模块封装及跨域技术详解.pptx

HTTP服务与模块封装及跨域技术详解.pptx

封装Ajax与跨域;课程大纲;1.引言; ; ; ;2.封装Ajax; ; ;(3)设计并约定对外接口的参数规格;(4)实现对外接口中参数处理

a.对外接口中创建xhr对象

functionajax(jsonObj){

varxhr=createXhr();

}

b.根据请求方式设置参数。

functionajax(jsonObj){

varxhr=createXhr();

};(5)实现对外接口中响应处理

a.根据请求方式设置回调函数。

functionajax(jsonObj){

//…

if(jsonObj.async===true){

xhr.onreadystatechange=function(){

if(xhr.readyState==4){

if(xhr.status==200){

jsonObj.success(JSON.parse(xhr.responseText));

}else{

jsonObj.error(xhr.statusText);

}

}

}

}

};(6)实现对外接口中发送处理

a.调用open+send函数。

functionajax(j

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档