2016-05-31 69 views
0

使用dojo/store/JsonRest發佈到REST API時,我收到以下錯誤。 我使用"X-Requested-With": null以避免預檢請求,但我仍然收到此錯誤。請求標題字段If-None-Match在預檢響應中不被Access-Control-Allow-Headers允許

API完全支持CORS。

任何想法如何解決?

請求標頭字段如果-Next-Match不被 允許在預檢響應中使用Access-Control-Allow-Headers。

 var store = new JsonRest({ 
      target: 'https://api.xxx.com/data', 
      headers: { 
       "Authorization": 'Bearer ' + 'd4c72611fc43ab44a46344d907a2b96964df2c91', 
       "X-Requested-With": null // no prefligh 
      } 
     }); 
     store.get('1-00').then(function (data) { 
      // ok works here 
      console.log('get', data) 
     }); 
     // post request 
     store.add({name:'test'}).then(function (data) { 
      // error here 
      console.log('add', data) 
     }); 

回答

0

我能解決使用中的頭"If-None-Match": null此問題的JsonRest

關於"If-None-Math"的有趣文檔可在HTTP/1.1 spec上找到。


var store = new JsonRest({ 
     target: 'https://api.xxx.com/data', 
     headers: { 
      "Authorization": 'Bearer ' + 'd4c72611fc43ab44a46344d907a2b96964df2c91', 
      "X-Requested-With": null`, // no prefligh 
      "If-None-Match": null // solve my issue 
     } 
    }); 
    store.get('1-00').then(function (data) { 
     // ok works here 
     console.log('get', data) 
    }); 
    // post request 
    store.add({name:'test'}).then(function (data) { 
     // ok works here 
     console.log('add', data) 
    }); 
相關問題