错误:请求仅在React-Native上终止

时间:2017-02-06 13:38:09

标签: php reactjs react-native cors

我使用原生基础

iOS 应用程序上工作
request
      .get('http://url_with_query')
      .then(function(res){
        console.log(res.body.data);
      })
      .catch(function(err){
        console.log(err);
      })

相同请求在 React Web应用程序中正常运行,但无法在 React-Native

中运行
  

React-Native调试控制台 - 结果如下

Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
    at Request.crossDomainError (client.js:616)
    at XMLHttpRequest.xhr.onreadystatechange (client.js:724)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:534)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:378)
    at XMLHttpRequest.js:482
    at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
    at MessageQueue.__callFunction (MessageQueue.js:236)
    at MessageQueue.js:108
    at guard (MessageQueue.js:46)
  

React Console - 结果

Response {req: Request, xhr: XMLHttpRequest, text: "{"data":[{"stock":"in stock","min_sale_qty":5,"max…_description":"Consumer Products"}],"status":200}", statusText: "OK", statusCode: 200…}
  

目标网址标题

header("Content-Type:application/json");
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');

0 个答案:

没有答案