由于工作需要长期使用Ajax,一个页面重复的AJAX请求太多,于是封装起来,只需要编写回调函数
/*
-------------
使用方法:
1.ajaxrequest()函数执行准备的参数(1.请求地址2.发送数据字符串拼接3.type值可选get/post4.回调函数名称)
example:
ajaxrequest('login.php','user=1&pass=2','post',dealwith);
function dealwith()
{
if(myxmlhttprequest.readyState==4)
{
//mes的值是login.php页面返回的值
var mes= myxmlhttprequest.responseText;
//如果页面输出的是json值,还需要进行eval处理
var mes_obj=eval("("+mes+")");
}
}
tip:ajaxrequest()以post方式发送数据user=1&pass=2,当服务器端收到请求并返回数据,此时
dealwith()方法来处理返回的数据
*/
//Allvariable 回调函数使用
var myxmlhttprequest="";
//Createxmlhttp 创建Ajax引擎
function getxmlhttpobject()
{
var xmlhttprequest;
if(window.ActiveXObject){
xmlhttprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
else{
xmlhttprequest=new XMLHttpRequest();
}
return xmlhttprequest;
}
//Createajaxrequest 发起请求
function ajaxrequest(url,data,type,callbackfunc)
{
myxmlhttprequest=getxmlhttpobject();
if (myxmlhttprequest)
{
myxmlhttprequest.open(type,url,true);
myxmlhttprequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
myxmlhttprequest.onreadystatechange=callbackfunc;
myxmlhttprequest.send(data);
}
}window.setInterval(method,time)方法本身会返回一个资源句柄,使用clearInterval(Intervalid)方法即可清除定时器<script> var num=0; //每隔1秒再控制台输...
离线缓存的开启实例使用apache设置 1.apache配置文件搜索Addtype,我的addtype已经存在项目,如下 AddType application/x-compress .Z AddType application/x-gz...
TmodJS是一套完整的前端模块框架。 虽然我们PHP框架自带各种模板引擎,但是始终是后端模板引擎。例如我们在使用ThinkPHP3.2.3中如果是Ajax异步加载页面,拼接HTML真的是很头疼的一件事情。...
https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body>...
开发需求如下,商品下单后需要指定送到日期:送达日期为周一 周三 周六 ,如果今天周一,用户选择周一即为下一周周一。代码如下:<html> <head> <meta charset="utf-8"> <title>...