我開發了一個PhoneGap應用程序,現在將其轉換為移動網站。除了一處小故障,一切都可以順利進行。我通過POST請求使用了某個第三方API,該API在該應用中可以正常運行,但在移動網站版本中卻無法運行。仔細查看后,看來AngularJS(我想實際上是瀏覽器)正在首先發送OPTIONS請求。今天,我對CORS有了很多了解,但是我似乎無法弄清楚如何完全禁用它。我沒有訪問該API的權限(因此無法在那一側進行更改),但他們已將我正在處理的域添加到其Access-Control-Allow-Origin標頭中。這是我正在談論的代碼: var request = { language: 'fr', barcodes: [ { barcode: 'somebarcode', description: 'Description goes here' } ] }; } var config = { headers: { 'Cache-Control': 'no-cache', 'Content-Type': 'application/json' } }; $http.post('http://somedomain.be/trackinginfo', request, config).success(function(data, status) { callback(undefined, data); }).error(function(data, status) { var err = new Error('Error message'); err.status = status; callback(err); });如何防止瀏覽器(或AngularJS)發送該OPTIONS請求,而直接跳到實際的POST請求?我正在使用AngularJS 1.2.0。提前致謝。
- 3 回答
- 0 關注
- 1666 瀏覽
添加回答
舉報
0/150
提交
取消