javascript常用代码段

一些我在开发中常用的代码段,方便自己copy,分享给大家,持续更新

JS定时刷新

setTimeout(function() {
            //执行代码
 }, 1500);

     

JQuery版ajax请求

$.post("http://localhost/ajax.jsp?",	
{
service:"txl",
pageNum:count
}
,function(result){
        //处理代码         
  },"json");

fetch版ajax请求

fetch('/login.do', {
     method: 'POST',
     credentials: "include",
     headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
     },
     body: 'userId=' + username + '&pass=' + pass + '&ABS_SchemeName=&valCode='
    })
    .then(response => {
     if (response.ok) {
      return response.text();
     }
     throw new Error('Network response was not ok.');
    })
    .then(responseText => {
     console.log(responseText);
    })
    .catch(e => {
     console.log(e.toString());
    })

猜你喜欢

转载自blog.csdn.net/lxyoucan/article/details/108356286