【问题标题】:CORS Origin Request Blocked in android applicationandroid 应用程序中的 CORS 原始请求被阻止
【发布时间】:2019-07-24 04:26:40
【问题描述】:

我们已经在 IONIC 中使用 anguler js 开发了 android 应用程序。

我们正在通过浏览器进行测试,但在控制台中出现错误。

跨域请求被阻止:同源策略不允许读取远程 http://example/abc/service.php 的资源(原因:CORS 请求未成功)

跨域请求被阻止:同源策略不允许读取远程 http://example/abc/service.php 的资源(原因:多次 CORS 请求未成功)

<?php
   header('Access-Control-Allow-Origin: *'); 
header('Access-Control-Allow-Headers: Content-Type');

error_reporting(E_ALL);



 ?>

尝试使用 Access-Control-Allow-Origin:null 和 Access-Control-Allow-Origin: example.com

还是不行

我们在 IONIC 框架

的 android 应用程序开发中使用 anguler js

帮助!如果你知道!

【问题讨论】:

    标签: javascript php android web-services ionic-framework


    【解决方案1】:

    “jsonp”你可以试试。

       <script type="text/javascript">
     jQuery(document).ready(function(){ 
        $.ajax({
             type: "get",
             async: false,
             url: "http://example/abc/service.php ",
             dataType: "jsonp",
             jsonp: "callback",
             jsonpCallback:"flightHandler",
             success: function(json){
                 alert(json.price);
             },
             error: function(){
                 alert('fail');
             }
         });
     });
     </script>
    

    【讨论】:

      【解决方案2】:

      你可以使用cordova-plugin-whitelist

      <access origin="http://example/" /> //specify your domain
      
      

      【讨论】:

        猜你喜欢
        • 2013-06-06
        • 2017-01-16
        • 2018-10-18
        • 2020-08-16
        • 2022-11-01
        • 2021-09-03
        • 2020-07-18
        • 2022-01-24
        • 2022-01-14
        相关资源
        最近更新 更多