Ajax URL 似乎被公司防火墙阻止

我正在开发一个加载另一个页面的 ajax 函数,以绕过 Shopify 上的 iframe 限制。我的问题似乎是 URL 被阻止或标题被剥离。没什么太复杂的,一切都按照我的需要通过以下方式工作:


function get_report() {

     var params = {

        type: "GET",

        url: "https://example.com/mypage.php",

        dataType: 'html',

        success:function(html) {

                    $("#content_div").load("https://example.com/mypage.php");

             },

        error: function(XMLHttpRequest, textStatus) {

               alert('Error : ' +XMLHttpRequest.response);

             }

     };

       

       jQuery.ajax(params);

};

<button onclick="get_report()">Get</button>

<div id="content_div"></div>

这可以通过公共网络毫无问题地工作。但是,当我的客户在公司防火墙后面使用它时,它无法加载页面。经过进一步检查,我的 php 所在的站点 URL 似乎也无法加载(我无法亲自确认)。以下是该页面的示例(如果相关):


<?php 

$allowedOrigins = [

    "https://myexample.com",

    "https://myexample2.com"

];


if (array_key_exists('HTTP_ORIGIN', $_SERVER)) { 

    $origin = $_SERVER['HTTP_ORIGIN']; 

} else if (array_key_exists('HTTP_REFERER', $_SERVER)) { 

    $origin = $_SERVER['HTTP_REFERER']; 

} else { 

    $origin = $_SERVER['REMOTE_ADDR']; 

}


if (in_array($origin, $allowedOrigins)) {

header("Access-Control-Allow-Origin: " .$origin);   

}

setcookie('cross-site-cookie', 'name', ['samesite' => 'None', 'secure' => true]);

?>


<!DOCTYPE HTML>

<html>

  <head>

    <meta charset="utf-8">

    <title>TEST ALT IFRAME</title>

  </head>

  <body>    

    <div><?php echo "IT WORKS"; ?></div>

  </body>

</html>

我知道的:

-通过访问 chrome 控制台步行客户端,列出零错误

- 当客户端尝试通过浏览器加载它时,URL 永远不会加载

-Ajax 从不给出错误响应

- 无法联系到网站管理员/IT 团队(我已尝试联系他们至少 4 个月)

我试过的:

-最近添加了元标记和!DOCTYPE(以防万一)

- 使用 W3C 验证 iframe 站点和 URL 站点

- 确认 iframe 站点和 URL 站点都适用于 VPN 和公共网络

-检查主要网络过滤组(语义、古阿尔托等)的正确分类并设置为“安全”。

我的问题:

-我如何确定 URL 是否被阻止或 ajax 请求被剥离?

- 如果网络正在过滤我的 ajax URL,我是在死胡同还是有其他选择?


小怪兽爱吃肉
浏览 151回答 1
1回答

一只萌萌小番薯

如何确定 URL 是否被阻止或 ajax 请求被剥离?如果出现网络错误,您可以在传递给 AJAX 调用的错误回调中对其进行响应:function get_report() {&nbsp; &nbsp; &nbsp;var params = {&nbsp; &nbsp; &nbsp; &nbsp; type: "GET",&nbsp; &nbsp; &nbsp; &nbsp; url: "https://example.com/mypage.php",&nbsp; &nbsp; &nbsp; &nbsp; dataType: 'html',&nbsp; &nbsp; &nbsp; &nbsp; success:function(html) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#content_div").load("https://example.com/mypage.php");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;},&nbsp; &nbsp; &nbsp; &nbsp; error: function(XMLHttpRequest, textStatus) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// inspect XMLHttpRequest to determine if network error occurred&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert('Error : ' +XMLHttpRequest.response);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp;};&nbsp; &nbsp; &nbsp; &nbsp;jQuery.ajax(params);};如果网络正在过滤我的 ajax URL,我是在死胡同还是有其他选择?您在应用程序级别处于死胡同,除非您愿意做一些真正令人费解的事情,例如拥有第三方服务,您知道不会有防火墙限制,请求页面,然后将其转发到可从该防火墙后面访问的服务。所以简短的回答是,不,不是真的(至少实际上不是)
打开App,查看更多内容
随时随地看视频慕课网APP