Не удалось выполнить «извлечение» в недопустимом режиме «Окно» - PullRequest
0 голосов
/ 12 июня 2018

Внезапно весь мой запрос на выборку в браузере выдает Failed to execute 'fetch' on 'Window' invalid mode.Они работали хорошо раньше.Кто-нибудь может дать подсказку на это?мой код, как показано ниже:

function request(params) {
  let { api, method, data } = params
  let localParm = {
    method: method,    
    mode: { mode: 'no-cors' },
    credentials: 'include',
    headers: typeof Headers !== 'undefined' ? new Headers({ 'content-type': 'application/x-www-form-urlencoded' }) : { 'content-type': 'application/x-www-form-urlencoded' }
  }
  let url = apiNames[api] || api
  if (method == "POST") {
    localParm.body = toQueryString(data)
  } else if (method == "GET") {       
    if (data) {
      url += ("?" + toQueryString(data || {}))
    }
  }
  const reqFunc = method === 'jsonp' ? fetchJsonp : fetch;
  return reqFunc(url, localParm).then((response) => {
    if (response.status === 200 || response.ok === true) {
      try {
        return response.json()        
      }catch(e){
        console.log('11')
      }
    } else {
        console.log('22')      
    }
  }).then((res) => {       
    return res        
  })
}

1 Ответ

0 голосов
/ 19 июня 2018

Удалить режим CORS из вашего заголовка.Кажется, вы начинаете использовать stage-0 или stage-2 в вашей спецификации JavaScript.В этой спецификации выборка по какой-то причине не позволяет режим CORS.

 let localParm = {
    method: method,    
    mode: { mode: 'no-cors' },
    credentials: 'include',
    headers: typeof Headers !== 'undefined' ? new Headers({ 'content-type': 'application/x-www-form-urlencoded' }) : { 'content-type': 'application/x-www-form-urlencoded' }
  } 

должен выглядеть как

let localParm = {
    method: method,    
    credentials: 'include', ....
...