Application Programming Interfaces (APIs) help programs interact with other programs.

程序间交互,使用API

The term AJAX originated as an acronym for Asynchronous JavaScript And XML.

JavaScript Object Notation (JSON)

二进制传输,接收为字符串 bytes → string

但默认是字符串而非对象,用JSON.parse(JSONString) 把JSON字符串转化为JS对象

用JSON.stringify(jsonObj) 把对象转换为字符串

stringify string ify 字符串化

//页面完成加载触发的事件 DOMContentLoaded
document.addEventListener('DOMContentLoaded',function(){
    // 原生js 给元素附加事件回调函数
    document.getElementById("getMessage").onclick = ()=>{}
  });
//getElementsByClassName 结果是个数组
document.getElementsByClassName('message')[0].textContent="Here is the message";

XMLHttpRequest 对象,含有很多属性和方法用来传输数据

Ajax 格式

//square[skwer]方的 curly['kɜrli]卷曲的
[ ] -> Square brackets represent an array
{ } -> Curly brackets represent an object
" " -> Double quotes represent a string.
//获得用户的gps 地理位置
if (navigator.geolocation){
  navigator.geolocation.getCurrentPosition(function(position) {
    document.getElementById('data').innerHTML="latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude;
  });
}

ajax 有哪些姿势

axios