ajax和fetch

一、ajaxajax

  var  ajax  =  new  XMLHttpRequest( )json

  ajax.open("post", "http://localhost:3000/api/articles")api

  ajax.setRequestHeader("Content-Type", "application/json")app

  ajax.send(JSON.stringify({"name": "aaa"}))post

  ajax.onreadystatechange  ==  function(){fetch

    if(ajax.readyState  ==  4  &&  ajax.status  ==  200){spa

      console.log(ajax.responseText)string

    }io

  }console

 

二、fetch

  fetch("http://localhost:3000/api/select/100?name=bbb")

  .then(response  => response.json())

  .then(data  =>  {

    console.log(data)

  })

相關文章
相關標籤/搜索