fetch resolves even if 404?

前端 未结 4 632
走了就别回头了
走了就别回头了 2020-11-27 07:22

Using this code :

fetch(\'notExists\') // <---- notice 
    .then(
        function(response)
        {
           alert(response.status)
        }
    )         


        
4条回答
  •  天涯浪人
    2020-11-27 07:48

    Use this code...

    fetch(`https://fercarvo.github.io/apps/integradora/DB/corpus.json`)
    .then(async (data) => {
        if (data.ok) {
            data = await data.json()
            //Here you have your data...
        }
    }).catch(e => console.log('Connection error', e))
    

提交回复
热议问题