search
HomeWeb Front-endJS Tutorialjs HTML5 Ajax implements file upload progress bar function_javascript skills

本文实例介绍了js结合HTML5 Ajax实现文件上传进度条功能,分享给大家供大家参考,具体内容如下

1.  lib.js

var Host = window.location.host;
//--Cookie
function setCookie(name,value)
{
  var Days = 30;
  var exp = new Date();
  exp.setTime(exp.getTime() + Days*24*60*60*1000);
  document.cookie = name + '='+ escape (value) + ';expires=' + exp.toGMTString();
}
function getCookie(name)
{
  var arr,reg=new RegExp('(^| )'+name+'=([^;]*)(;|$)');
  if(arr=document.cookie.match(reg))
    return unescape(arr[2]);
  else
    return null;
}
//--Dom & String
var get = {
   //-- 获得Dom Id
   Id:function(obj)
   {
     return is.object(obj) ? obj : (document.getElementById(obj));
   },
   //--获得Body
   body:function()
   {
     return document.body;
   },
   //-- 通过Html 标签取对象
   Tag:function(obj, Tagname) 
   {
    return obj.getElementsByTagName(Tagname);
   },
   //-- 通过Name 来取对象
   Name:function (Name) 
   {
     return document.getElementsByName(Name);
   },
   //-- Url编码转换
   encode:function (str) 
   {
    return encodeURIComponent(str);
   },
   filepath:function (obj,callback) 
   {
     window.URL = window.URL || window.webkitURL;
     img = new Image();
     var reader = new FileReader();
     reader.readAsDataURL(get.Id(obj).files[0]);
     reader.onload = function(e){
       callback(this.result);
       source = this.result;
     }
    // return window.URL.createObjectURL(get.Id(obj).files[0]);
   }
}
var set = {
  //-- url 跳转
  url:function(URL) 
  {
    window.location.href = URL;
  },
  //-- 页面刷新
  reload:function() 
  {
    window.location.reload();
  },
  //-- 动态设置 标签内容 @ obj 为标签内容,text 为内容
  html:function (obj, text) 
  {
     obj.innerHTML = text;
  }
}
var string = {
  //-- 将字符转换成Json
  toJson:function(str) 
  {
    return eval('('+str+')');
  },
  //-- 不区分大小写判断 相等true , 
  eqlower:function(str1, str2) 
  {
    if(str1.toLowerCase() == str2.toLowerCase()){
      return true;
    }
    return false;
  }
}
var is = {
  //-- 是否是IE浏览器,用此来判断是否支持HTML5,低于IE10的返回false,由于 IE采用 V8 JavaScript引擎
  html5:function () 
  {
    return (!/*@cc_on!@*/~0x1111111111111111) ? false : true;
  },
  //--验证身份证,并且返回身份证,性别,住址,年龄
  Card:function (sId) {
      
    var card_area={
         
        11:'北京', 12:'天津', 13:'河北', 14:'山西', 21:'辽宁', 15:'内蒙古',
 
        22:'吉林', 31:'上海', 32:'江苏', 33:'浙江', 34:'安徽', 23:'黑龙江',
 
        35:'福建', 36:'江西', 37:'山东', 41:'河南', 42:'湖北', 43:'湖南',
 
        44:'广东', 45:'广西', 46:'海南', 50:'重庆', 51:'四川', 52:'贵州',
 
        53:'云南', 54:'西藏', 61:'陕西', 62:'甘肃', 63:'青海', 64:'宁夏',
 
        65:'新疆', 71:'台湾', 81:'香港', 82:'澳门', 91:'国外'
 
      };
      var iSum=0
      var info=''
      var card_info=Array(2);
      var error = '';
      sId=sId.replace(/x$/i,'a');       
       
      if (sId.length==0){      
        error = '请填写你的身份证';
        return false;
      } 
       
      if (null == card_area[parseInt(sId.substr(0,2))]) {
        error = '非法证件你的地区填写有错误请仔细填写';
        return false;
      }
       
      sBirthday=sId.substr(6,4)+'-'+Number(sId.substr(10,2)) + '-'+Number(sId.substr(12,2));
      var d = new Date(sBirthday.replace(/-/g,'/'));
 
      if (sBirthday!=(d.getFullYear()+'-'+ (d.getMonth()+1) + '-' + d.getDate())) {
        error = '非法证件你的生日填写有错误请仔细填写';
        return false;
      }
 
      for(var i = 17; i>=0; i--)
      {
        iSum += (Math.pow(2,i) % 11) * 
        parseInt(sId.charAt(17 - i),11)
      }      
 
      if (1 != iSum%11) {
        error = '非法证号你确认你是地球人请认真填写哦~~~~'; 
        return false;
 
      }
       
      if (sId.length>19){
        error = '你确认你的身份证是有效证件?';
        return false;
      }
       
      card_info[0] = card_area[parseInt(sId.substr(0, 2))];
      card_info[1] = sBirthday;
      card_info[2] = sId.substr(16, 1) % 2 ? '男' : '女';
      return card_info;
   
  },
  //--获取变量的类型, object,string,int.....等
  type:function(type) 
  {
    if(is.object(type)) {
      return 'object';
    }else if (is.string(type)) {
      return 'string';
    }else if (is.int(type)) {
      return 'int';
    }else if (is.double(type)) {
      return 'double';
    }else {
      return 'null';
    }
  },
  //-- 变量是否是对象,返回 true|false
  object:function(type) 
  {
    return 'object' == typeof(type) ? true:false;
  },
  //-- 变量是否是字符串 , 返回 true|false
  string:function(type) 
  {
    return 'string' == typeof(type) ? true:false;
  },
  //-- 变量是否是整型,返回 true|false
  int:function(type) 
  {
    if ('number' == typeof(type)) {
      if(0 > type.toString().indexOf('.')) {
        return true;
      }
    }
    return false;
  },
  //-- 变量是否是小数,返回 true|false
  double:function(type) 
  {
    if('number' == typeof(type)) {
      if (0<=type.toString().indexOf('.')) {
        return true;
      }
    }
    return false;
  }
}
var file = {
  //--异步文件上传
  upload:function (json) 
  {  
    var post = new XMLHttpRequest();
    var FLIE = new Object();
    var json = is.object(json) &#63; json : string.toJson(json);
    var dataType = string.eqlower(json.dataType,'json') &#63; true : false;
    var fileSize = 0;
    if(!json.url&&json.error) {
      json.error(404);
      return;
    }
    if(!is.object(json.file)) {
      FLIE.id = get.Id(json.file);
      //-- 大文件处理 
      if(json.maxfile) { 
       
        //--文件总大小
        fileSize = file.getSize(FLIE.id);
        //--以2M为单位进行文件切割
        shardSize = 1024 * 1024 << 1;      
        //--总片数
        shardCount = Math.ceil(fileSize / shardSize); 
        for(var i = 0; i < shardCount; ++i)
        {
          //--计算每一片的起始与结束位置
          var start = i * shardSize;
          var end = Math.min(fileSize, start + shardSize);
          var formData = new FormData();
          //--slice方法用于切出文件的一部分          
          formData.append(json.file, FLIE.id.files[0].slice(start,end));         
          formData.append("total", shardCount); //总片数
          formData.append("index", i + 1);    //当前是第几片
          post.upload.addEventListener('progress', callback, false);
          post.open('post', json.url, true); // 异步传输
          post.send(formData);
          post.upload.onprogress = function (ev) {
           if(file.getProgress(ev) == 100) {
              json.success(ev);
           }
          }
        }
      }else {
        var formData = new FormData();
        formData.append(json.file, FLIE.id.files[0]);
        if (json.progress) {
          post.upload.addEventListener('progress', json.progress, false);
        }
        post.open('post', json.url, true); // 异步传输
        post.send(formData);
        /*post.upload.onprogress = function (ev) {
         if(file.getProgress(ev) == 100) {
            json.success(ev);
         }
        }*/
        post.onreadystatechange = function () {
          switch (post.readyState) {
            case 1:{break;}
            case 2:{break;}
            case 3:{break;}
            case 4:{
              if (post.status == 200 || post.status == 0) { 
               json.success(string.toJson(post.responseText));
              }
              break;
            }
          }
        }
      }
    }
     
  },
  //-- 获得上传文件的进度值
  getProgress:function (evt) {
    var percentComplete = Math.round(evt.loaded * 100 / evt.total);
    return percentComplete.toString();
  },
  //-- 获得文件的大小
  getSize:function (file) {
    var FILE = get.Id(file).files[0];
    var fileSize = 0;
     
    if (file.size > 1024 * 1024) {
      fileSize = (Math.round(FILE.size * 100 / (1024 * 1024)) / 100).toString();
    } else {
      fileSize = (Math.round(FILE.size * 100 / 1024) / 100).toString();
    }
    return fileSize;
  },
  //-- 获得文件的类型
  getType:function (file) {
    var FILE = get.Id(file).files[0];
    return FILE.type;
  },
  //-- 获得文件的名字
  getName:function (file) {
    var FILE = get.Id(file).files[0];
    return FILE.name;
  },
  //--包含文件
  include:function (path) {
     
  }
}
//--Ajax数据提交类
var Call = {
    /**
     * 参数为json对象|Json字符串, 
     * @type post|get 默认为get ,请求方式
     * @url String 字符串型 ,请求地址
     * @loading bool true|false 是否开启动画
     * @time int 动画时间 如果 loading 为false 则不用设置这个参数
     * @data Json | String 提交的数据
     * @sucess 回调函数 这个必须有  
     */
    Ajax:function(json){
      var json = is.object(json)&#63;json:string.toJson(json);
      var type = (json.type == undefined) || (json.type == '') &#63; 'get' : json.type; ;
      var url = (json.url == undefined) || (json.url == '') &#63; alert('请求url不能为空') : json.url;
      var loading = (json.Loading == undefined) || (json.Loading == '') &#63; false : json.Loading;    
      var time = (json.time == undefined) || (json.time == '') &#63; 2000 : json.time;  
      var dataType = string.eqlower(json.dataType,'json') &#63; 'json' : 'string';
      if(loading) { var L = Loading.start(); }
      var data = '';     
      if(is.object(json.data)) {
        if(json.data) {
          for(d in json.data) {
           data = data + d + '=' + json.data[d] + '&';
          }
        }
        if(string.eqlower(json.type,'get')) {
          data ='&#63;' + data.substring(0, data.length-1);
        }
      }else{
        if(json.data.length>=1) {
          data = json.data.indexOf('&#63;') < 0 &#63; '&#63;'+json.data:json.data+'';
        }
      }
      try {
        //--IE高版本创建XMLHTTP
        XMLHttpReq = new ActiveXObject('Msxml2.XMLHTTP');
      }
      catch(E) { 
        try { 
          XMLHttpReq = new ActiveXObject('Microsoft.XMLHTTP');//IE低版本创建XMLHTTP 
        } 
        catch(E) { 
          XMLHttpReq = new XMLHttpRequest();//兼容非IE浏览器,直接创建XMLHTTP对象 
        } 
      } 
      if(XMLHttpReq) {
        if (string.eqlower(json.type, 'post')) {          
          XMLHttpReq.open('post', url, true);
          XMLHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          XMLHttpReq.send(data);
        }else if (string.eqlower(json.type, 'get')) {
          XMLHttpReq.open('get', url+data, true);         
          XMLHttpReq.send(null);
        }
        XMLHttpReq.onreadystatechange = function () { 
           
          switch (XMLHttpReq.readyState) {
            case 1:{break;}
            case 2:{break;}
            case 3:{break;}
            case 4:{
              if (XMLHttpReq.status == 200 || XMLHttpReq.status == 0) { 
                if (loading) {
                  setTimeout(function(){
                    Loading.stop(L);
                    if(json.dataType == 'json') 
                     json.success(string.toJson(XMLHttpReq.responseText));
                    else
                     json.success(XMLHttpReq.responseText) 
                  }, time*1000);
                }else {
   
                    if(json.dataType == 'json') 
                     json.success(string.toJson(XMLHttpReq.responseText));
                    else
                     json.success(XMLHttpReq.responseText) 
                }
              }
              break;
            }
          }
        }
      }
    }
}
var Loading = {
  //-- Ajax动画
  start:function(){
    var d = add.Dom(document.body,'style');
    d.innerHTML = '@keyframes d{from {left:0px;}to {left:98%;}}';
    var back = add.Dom(document.body, 'div');
    var d0 = add.Dom(back, 'div');
    var d1 = add.Dom(d0, 'div');
    var d2 = add.Dom(d0, 'div');
    var d3 = add.Dom(d0, 'div');
    var d4 = add.Dom(d0, 'div');
    add.Attr(back, 'style', 'width:100%;height:100%;filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; background:#000; position:fixed; left:0px; top:0px; z-index;1000;');
    add.Attr(d0, 'style', 'position:relative; top:50%; width:100%; height:30px;');
    add.Attr(d1, 'style', 'height:15px; width:15px; position:absolute; background:#ABCDEF; animation:d 2s infinite; -moz-border-radius:15px; -webkit-border-radius: 15px; border-radius: 15px 15px 15px 15px; ');
    add.Attr(d2, 'style', 'height:15px; width:15px; position:absolute; background:#ABCDEF; animation:d 3s infinite; -moz-border-radius:15px; -webkit-border-radius: 15px; border-radius: 15px 15px 15px 15px; ');   
    add.Attr(d3, 'style', 'height:15px; width:15px; position:absolute; background:#ABCDEF; animation:d 4s infinite; -moz-border-radius:15px; -webkit-border-radius: 15px; border-radius: 15px 15px 15px 15px; ');
    add.Attr(d4, 'style', 'height:15px; width:15px; position:absolute; background:#ABCDEF; animation:d 5s infinite; -moz-border-radius:15px; -webkit-border-radius: 15px; border-radius: 15px 15px 15px 15px; ');   
    var div = { domback:back, dom0:d0, dom1:d1, dom2:d2, dom3:d3, dom4:d4 }
    return div;
  },
  //-- Ajax停止动画
  stop:function(d) {
    d.dom0.parentNode.removeChild(d.dom0);
    d.dom1.parentNode.removeChild(d.dom1);
    d.dom2.parentNode.removeChild(d.dom2);
    d.dom3.parentNode.removeChild(d.dom3);
    d.dom4.parentNode.removeChild(d.dom4);
    d.domback.parentNode.removeChild(d.domback);
  }
   
}
var del = {
  Dom:function(obj) {
    obj.parentNode.removeChild(obj);
  }  
}
var add = {
  //--动态添加Dom节点
  Dom:function (obj,dom) {
    var dom = document.createElement(dom);
    get.Id(obj).appendChild(dom);
    return dom;
  },
  //-- 动态添加属性
  Attr:function(obj,key,value){
    obj.setAttribute(key, value);
    return obj;
  }
}
//--URL编码
function url(Str){
  return decodeURI(Str);
}
/**
 * 模板字符串,语法标签采用<js></js> 
 * 完全遵循javascript原生语法
 * @param template
 * @param vars
 * @returns {Function}
 */
function js_template(template, vars) {
   
  //唯一分隔标志字符串
  var split = '_{' + Math.random() + '}_';
 
  //消除换行符
  var estr = template.replace(/\n|\r|\t/g, '');
 
  var js = [];
  /****
   * 匹配标签<js> ...</js>--并且替换为特定的分隔串,
   * 并将匹配的js代码放入js数组中备用
   * */
  estr = estr.replace(/<js>(.*&#63;)<\/js>/g, function ($0, $1) {
    js.push($1);
    return split;
  });
 
  /*根据特定的分隔串分隔得到普通text文本串的数组*/
  var text = estr.split(split);
  estr = " var output='';";
  /****
   * 0101010---0为text[]元素,1为js[]元素
   * 重新串起来连接为可执行eval的estr
   * **/
  for (var i = 0; i < js.length; ++i) {
    estr += 'output+=text[' + i + '];';
    estr += js[i];
 
  }
  estr += 'output+=text[' + js.length + '];';
 
  estr += 'return output;';
 
  var fun =new Function('vars','text',estr);
  return function(data){
    return fun.apply(null,[data,text]);
  }
}

2.  add.html

<!DOCTYPE html>
 
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"><title>Lumino Pro - Dashboard</title>
<link href="__SOURCE__/css/bootstrap.min.css" rel="stylesheet">
<link href="__SOURCE__/css/datepicker3.css" rel="stylesheet">
<link href="__SOURCE__/css/styles.css" rel="stylesheet">
<link href="__SOURCE__/css/Table.css" rel="stylesheet">
<link href="__SOURCE__/css/dt.css" rel="stylesheet">
<link href="__SOURCE__/css/plus/buttons.css" rel="stylesheet">
<link href="__SOURCE__/css/file.css" rel="stylesheet">
<link href="__SOURCE__/css/webuploader.css" rel="stylesheet">
<link href="__SOURCE__/css/plus/bootstrap-switch.min.css" rel="stylesheet">
<link href='http://fonts.useso.com/css&#63;family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css'>
<!--[if lt IE 9]>
<link href="__SOURCE__/css/rgba-fallback.css" rel="stylesheet">
<script src="__SOURCE__/js/html5shiv.js"></script>
<script src="__SOURCE__/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
  <include file="Apps/Admin/View/include/nav.html"/>    
  <div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
    <form role="search">
      <div class="form-group">
        <input type="text" class="form-control" placeholder="Search">
      </div>
    </form>
  <include file="Apps/Admin/View/include/menu.html"/>
  </div><!--/.sidebar-->   
  <div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">     
    <div class="row">
      <ol class="breadcrumb">
        <li><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
        <li class="active">Dashboard</li>
      </ol>
    </div>
    <div class="row col-no-gutter-container">
    <div class="panel panel-default">
        <div class="panel-heading">Banner添加 
          <button id='up' type="button" style='float:right; margin:4px;"' class="btn btn-default"><span class="glyphicon glyphicon-plus"></span>上传</button>
          <button id='add' type="button" style='float:right; margin:4px;"' class="btn btn-default"><span class="glyphicon glyphicon-plus"></span>确定添加</button>
        </div>
          <div class="panel-body">
            <div class="canvas-wrapper">
              <form id='banner'>
               <dl class='dt'>
                <dd><label>Banner名字</label></dd>
                <dt>
                  <div class="form-group has-success">
                    <input name='name' class="form-control" placeholder="Banner名字" value=''>
                  </div>
                </dt>
                <div style='clear:both;'></div>
                <dd><label>Banner类型:</label></dd>
                <dt>
                  <div class="form-group has-warning">
                    <select name='type' class="form-control" style='background:rgb(31,45,55); color:#FFF;'>
                      <option value='1' style=' font-size:18px;'>首页</option>
                      <option value='2' style=' font-size:18px;'>内页广告</option>
                    </select>
                  </div>
                </dt>
                <div style='clear:both;'></div>
                <dd><label>Banner链接地址:</label></dd>
                <dt>
                  <div class="form-group has-warning">
                    <input name='link' class="form-control" placeholder="Banner链接地址" value=''>
                  </div>
                </dt>
               </dl>
               <dl class='dt'>
                <dd><label>Banner上传:</label></dd>
                <dt>
                  <div class="form-group has-warning">
                    <input class="form-control" type = 'button' value='选择文件'>
                    <input id='files' type='file' class="file">
                  </div>
                </dt>
                <div style='clear:both;'></div>
                <dd><label>文件类型:</label></dd>
                <dt>
                  <div class="form-group has-warning">
                    <div id='filetype' class='left' style='padding-top:2px;'></div>
                  </div>
                </dt>
                <div style='clear:both;'></div>
                <dd><label>文件上传进度:</label></dd>
                <dt>
                  <div class='form-control' style='padding:2px; height:26px; overflow:hidden;'>
                    <!-- <div id='progress' style='background:#ABCDEF; width:0px; height:22px;'></div> -->
                    <progress id='progress' max="100" value='0' style='width:100%; height:22px; background:#30a5ff;'>o(︶︿︶)o</progress>
                    <div id='gress' height:0px; style='padding-top:2px; color:#FFF; position:relative; bottom:28px; left:40%;'></div>
                  </div>
                  <div id='fileSize' class='right' style='padding-top:2px;'>
                    <span class='left'></span>
                    <span></span>
                  </div>
                </dt>
                </dl>
              </form>
              <div style='clear:both;'></div>
              <div class='fixed-table-container' style='height:244px;'>
                <img  class="left lazy"  src="/static/imghwm/default1.png"  data-src="__SOURCE__/js/jquery-1.11.1.min.js"  id ='thmb' alt="js HTML5 Ajax implements file upload progress bar function_javascript skills" >
                <div>
                  <ul style='display:none;'>
                    <li><span>文件大小:</span><p>22222kb</p></li>
                    <li><span>文件路径:</span><p>22222kb</p></li>
                    <li><span>图片高度:</span><p>22222kb</p></li>
                    <li><span>图片宽度:</span><p>22222kb</p></li>
                  </ul>
                </div>
              </div>
            </div>            
          </div>
        </div>
                   
    </div>  <!--/.main-->
  </div>
               
  <script></script>
  <script src="__SOURCE__/js/bootstrap.min.js"></script>
  <script src="__SOURCE__/js/file.js"></script>
  <script type="text/javascript" src="__SOURCE__/js/plus/bootstrap-datetimepicker.de.js" charset="UTF-8"></script>
  <script src="__SOURCE__/js/plus/bootstrap-switch.min.js"></script>
  <script src="__SOURCE__/js/table.js"></script>
  <script type="text/javascript" src='__SOURCE__/js/lib.js'></script>
  <script>
    var data = new Object();
    get.Id('files').onchange = function () {
      get.filepath(this,function(str){
        get.Id('thmb').src = str;
      });
      set.html(filetype,file.getName('files'));
      get.Id('progress').value = 0;
      set.html(get.Id('gress'),'');
      set.html(get.Tag(get.Id('fileSize'), 'span')[0], file.getSize('files') + 'KB');
      set.html(get.Tag(get.Id('fileSize'), 'span')[1], '/0kb');
    }
    get.Id('up').onclick = function () {
      if(file.getSize('files')<=0) {
        return false;
      }
      file.upload({
        form:'banner', //form的id
        url:'{:U('Banner/add',0,0)}', //上传请求文件的地址
        //maxfile:true, //是否启用大文件上传
        dataType:'json',
        progress:function(ev) { //--上传中的进度回掉函数
          get.Id('progress').value = file.getProgress(ev);
          //获得上传进度用file.getProgress(ev)
          set.html(get.Id('gress'),file.getProgress(ev)+'%');
           
          set.html(get.Tag(get.Id('fileSize'), 'span')[1], '/' + file.getProgress(ev) * (file.getSize('files') / 100 >>0) + 'KB');
        },
        file:'files', //--文件输入框的id
        //--上传完成后,后台返回的回调函数
        success:function(e){
          set.html(get.Tag(get.Id('fileSize'), 'span')[1], '/' + file.getSize('files') + 'KB');
          set.html(get.Id('gress'),'上传完成');        
          data.bannerWidth = e.bannerWidth;
          data.bannerHeight = e.bannerHeight;
          data.bannerTyle = e.bannerTyle;
          data.bannerImg = e.bannerImg;
        }
      });
    }
    get.Id('add').onclick = function () {
      data.name = get.Name('name')[0].value;
      data.type = get.Name('type')[0].value;
      data.link = get.Name('link')[0].value;
      data.act = 'add';
      Call.Ajax({
        type:'post',  // 请求方式
        Loading:true, // 是否启动动画
        time:5,  //动画显示几秒
        url:'{:U('Banner/add',0,0)}&#63;act=add', //请求地址
        data:data,  //发送的数据 
        dataType:'json', //Ajax返回的数据类型 ,可以是String
        success:function (e) { //回调函数
          set.url(e.url);  
        }
      });
    }
  </script>
</body>
</html>

希望本文所述对大家学习javascript程序设计有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.