Guoguomix

jsp主要就是用之前的jsonArray读取

ajax可以设置个定时器,然后设置的方法,至于方法是今天学习到的

function ajax(method,data,url,success){
var xhr=null;
try{
xhr=new XMLHttpRequest("Microsoft.XMLHTTP");
}catch(e){
xhr=new XMLHttpRequest();
}
if(method==\'get\'){  //有data记得在url上加
url+=\'?\'+data;
}
xhr.open(method,url,true);
if(method==\'get\'){
xhr.send();}
else{
xhr.setRequestHeader(\'content-type\', \'application/x-www-form-urlencoded\');  //因为是post方法是由于通过请求头来传输,所以要设置请求头
xhr.send(data);
}

xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){    //回调函数操作不同,判断存在不
success&&success(xhr.responseText);
}}}}

 

//这是定时器的使用

setInterval(function(){
ajax(\'get\',\'\',\'newupadate.jsp\',function(data){
var data=eval(\'(\'+data+\')\');
var p;
for(var i=0;i<data.length;i++){
p+=\'<li>\'+data[i].content+data[i].date+\'</li>\';
}
document.getElementsByTagName("ul")[0].innerHTML=p;
});
},
1000);

分类:

技术点:

相关文章:

  • 2020-06-19
  • 2021-12-23
  • 2021-12-05
  • 2021-12-05
  • 2021-12-15
  • 2021-12-05
  • 2018-08-24
  • 2021-10-26
猜你喜欢
  • 2021-11-14
  • 2021-12-15
  • 2021-12-05
  • 2021-12-15
  • 2021-09-15
  • 2021-12-21
  • 2021-04-08
相关资源
相似解决方案