📜  js 获取状态为 500 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:19.133000             🧑  作者: Mango

代码示例1
fetch('http://some-site.com/api/some.json')  
  .then(function(response) {                      // first then()
      if(response.ok)
      {
        return response.text();         
      }

      throw new Error('Something went wrong.');
  })  
  .then(function(text) {                          // second then()
    console.log('Request successful', text);  
  })  
  .catch(function(error) {                        // catch
    console.log('Request failed', error);
  });