HLJ 发布于
2022-09-29 23:33:05

js捕捉异常并上传log日志到服务器上

js代码

try{

  // 设置错误的接口参数
  const params = {
    google: 't-100142',
    operating: 'select'
  }
  getDataApi(paramsd).then(res => {
   
  })
}
catch(err){
  // 扑捉异常
  const text = `日志异常内容:${err}`
  const blob = new Blob([text], {type: 'text/plain'});
  let formData = new FormData();
      formData.append("file", blob, `${new Date().getTime()}.txt`);

  uploadException(formData).then(res => {

  })
}

服务器代码

<?PHP
move_uploaded_file($_FILES["file"]["tmp_name"], "log/".$_FILES["file"]["name"])
?>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2022-09-29/603.html
最后生成于 2022-11-21 22:22:30