What is the vanilla JS version of Jquery's $.getJSON

前端 未结 4 1851
礼貌的吻别
礼貌的吻别 2021-02-05 13:07

I need to build a project to get into a JS bootcamp I am applying for. They tell me I may only use vanilla JS, specifically that frameworks and Jquery are not permitted. Up to

4条回答
  •  悲&欢浪女
    2021-02-05 13:43

    ES6 has Fetch API which provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.

    It is easier than XMLHttpRequest.

    fetch(url) // Call the fetch function passing the url of the API as a parameter
    .then(function() {
        // Your code for handling the data you get from the API
    })
    .catch(function() {
        // This is where you run code if the server returns any errors
    });
    

提交回复
热议问题