首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查运行在iPhone Safari上的Ajax请求的状态?

如何检查运行在iPhone Safari上的Ajax请求的状态?
EN

Stack Overflow用户
提问于 2019-04-18 19:18:22
回答 2查看 1.5K关注 0票数 5

我在我的网站上加载了这个代码

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">

<head>
    <title>fingerprinting</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
</head>

<body>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <h1>page loaded.</h1>
    <h1 id="model"></h1>


    <script type="text/javascript">

        // console.log(window);
        function getIPhoneModel() {
            // Create a canvas element which can be used to retrieve information about the GPU.
            var canvas = document.createElement("canvas");
            if (canvas) {
                var context = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
                if (context) {
                    var info = context.getExtension("WEBGL_debug_renderer_info");
                    if (info) {
                        var renderer = context.getParameter(info.UNMASKED_RENDERER_WEBGL);
                    }
                }
            }

            // iPhone X
            if ((window.screen.height / window.screen.width == 812 / 375) && (window.devicePixelRatio == 3)) {
                return "iPhone X";
            } else if ((window.screen.height / window.screen.width == 896 / 414) && (window.devicePixelRatio == 3)) {
                return "iPhone XS Max";
            } else if ((window.screen.height / window.screen.width == 896 / 414) && (window.devicePixelRatio == 2)) {
                return "iPhone XR";
            } else if ((window.screen.height / window.screen.width == 1024 / 768) && (window.devicePixelRatio == 2)) {
                return "iPad 4";
            }
            else if ((window.screen.height / window.screen.width == 736 / 414) && (window.devicePixelRatio == 3)) {
                switch (renderer) {
                    default:
                    return "iPhone 6 Plus, 6s Plus, 7 Plus or 8 Plus";
                    case "Apple A8 GPU":
                    return "iPhone 6 Plus";
                    case "Apple A9 GPU":
                    return "iPhone 6s Plus";
                    case "Apple A10 GPU":
                    return "iPhone 7 Plus";
                    case "Apple A11 GPU":
                    return "iPhone 8 Plus";
                }
                // iPhone 6+/6s+/7+ and 8+ in zoom mode
            } else if ((window.screen.height / window.screen.width == 667 / 375) && (window.devicePixelRatio == 3)) {
                switch(renderer) {
                    default:
                    return "iPhone 6 Plus, 6s Plus, 7 Plus or 8 Plus (display zoom)";
                    case "Apple A8 GPU":
                    return "iPhone 6 Plus (display zoom)";
                    case "Apple A9 GPU":
                    return "iPhone 6s Plus (display zoom)";
                    case "Apple A10 GPU":
                    return "iPhone 7 Plus (display zoom)";
                    case "Apple A11 GPU":
                    return "iPhone 8 Plus (display zoom)";
                }
                // iPhone 6/6s/7 and 8
            } else if ((window.screen.height / window.screen.width == 667 / 375) && (window.devicePixelRatio == 2)) {
                switch(renderer) {
                    default:
                    return "iPhone 6, 6s, 7 or 8";
                    case "Apple A8 GPU":
                    return "iPhone 6";
                    case "Apple A9 GPU":
                    return "iPhone 6s";
                    case "Apple A10 GPU":
                    return "iPhone 7";
                    case "Apple A11 GPU":
                    return "iPhone 8";
                }
                // iPhone 5/5C/5s/SE or 6/6s/7 and 8 in zoom mode
            } else if ((window.screen.height / window.screen.width == 1.775) && (window.devicePixelRatio == 2)) {
                switch(renderer) {
                    default:
                    return "iPhone 5, 5C, 5S, SE or 6, 6s, 7 and 8 (display zoom)";
                    case "PowerVR SGX 543":
                    return "iPhone 5 or 5c";
                    case "Apple A7 GPU":
                    return "iPhone 5s";
                    case "Apple A8 GPU":
                    return "iPhone 6 (display zoom)";
                    case "Apple A9 GPU":
                    return "iPhone SE or 6s (display zoom)";
                    case "Apple A10 GPU":
                    return "iPhone 7 (display zoom)";
                    case "Apple A11 GPU":
                    return "iPhone 8 (display zoom)";
                }
                // iPhone 4/4s
            } else if ((window.screen.height / window.screen.width == 1.5) && (window.devicePixelRatio == 2)) {
                switch(renderer) {
                    default:
                    return "iPhone 4 or 4s";
                    case "PowerVR SGX 535":
                    return "iPhone 4";
                    case "PowerVR SGX 543":
                    return "iPhone 4s";
                }
                // iPhone 1/3G/3GS
            } else if ((window.screen.height / window.screen.width == 1.5) && (window.devicePixelRatio == 1)) {
                switch(renderer) {
                    default:
                    return "iPhone 1, 3G or 3GS";
                    case "ALP0298C05":
                    return "iPhone 3GS";
                    case "S5L8900":
                    return "iPhone 1, 3G";
                }
            } else {
                return "Not an iPhone";
            }
        }

        var model = getIPhoneModel()
        console.log(model);

        $('#model').text(model);

        var currentUrl = window.location.href;
        var newUrl = currentUrl.replace("fingerprinting", "fingerprinting/tasks");

        // alert(newUrl);

        $.ajax({
            method: 'POST',
            url: "{{ $APP_URL }}fingerprinting/store",
            data: {'original_uri':'{!! $original_uri !!}', 'model' : model,},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            success: function(response){
                console.log(response);
                window.location.href = newUrl;
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(JSON.stringify(jqXHR));
                console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
            }
        });


    </script>

    <h1>JS finished loaded.</h1>

</body>

</html>

页面底部有Ajax。我确信为什么它不触发iPhone Safari。或者它正在被执行,但也有一些错误。

注意:

  • 在Mac上Chrome或Safari上的相同代码。✅
  • Ajax确实触发了,而且工作正常。✅

Ajax似乎不会在iPhone Safari上触发

我是否使用了iPhone上Safari无法识别的旧语法?

我们将如何进一步调试它呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-23 08:40:46

您可以使用Safari WebInspector

您将需要一个带有Mac已安装

您需要在ip上本地运行服务器。打开您的终端并运行ifconfig,找到您的ip,或者复制ethernetenp1s0或为wifi复制wlp2s0

代码语言:javascript
复制
~ $ ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.38  netmask 255.255.255.0  broadcast 192.168.1.255

wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.6  netmask 255.255.255.0  broadcast 192.168.1.255

在此ip上使用您的网站运行您的服务器。对于rails,我运行rails server -b 192.168.1.38 -p 3000-b代表ip binding-p代表端口。

打开Xcode和启动一个新的模拟器,或者通过usb连接设备。

按照本指令在iphone模拟器上打开http://192.168.1.38:3000

如果您的很难配置您的iphone来调试,请记住这是指示中的重要步骤。

  1. 如果您使用的是Webinspector USB,则只需要启用选项。您不需要在模拟器设备上标记此选项。我和在模拟器上没有能够运行网络巡查员。
  2. 运行模拟器并使用移动safari浏览器打开页面后,您需要打开桌面 safari浏览器,并通过检查Show develop menu in menu bar在菜单栏中启用Develop

如果在菜单栏中看不到" develop“,请转到菜单栏并单击"Safari > Preferences > Advanced”并选择“显示菜单栏中的发展菜单”复选框。

  1. 从菜单栏Develop -> Simulator or Iphone -> Your Page中选择safari

在developer工具栏中,打开指南中显示的Timelines/Network RequestNetwork,以检查网络请求。

检查您的服务器日志,查看后端是否正在接收AJAX请求,或者检查您的phone simulator日志,因为您可能会看到一些与证书或其他原因相关的错误。你必须在网上研究这些错误的解决方案。

当我用xcode构建这个项目时,我还可以从xcode内部的电话中看到控制台日志。

票数 6
EN

Stack Overflow用户

发布于 2019-04-25 15:10:30

从您的问题中,我了解您希望能够在移动设备上进行调试,而不是在桌面上调试?如果您使用的是iPhone 7或更高版本,则可以在iPhone settings中打开一个WebInspector

转到Settings> Safari> Advanced (它在屏幕底部),在那里有一个按钮,您可以在那里打开WebInspector。这样,您就可以在iPhone上读取控制台。

“WebInspector”在iPhone 7中是新的;旧的iPhones (6或6以下)使用的'DebugConsole'可以通过“设置”菜单以相同的方式访问。WebInspector的优点是,当iPhone连接到Mac时,您可以在桌面safari中显示iPhone检查器。(从Safari菜单中选择'Develop'>'Show WebInspector‘’.

默认情况下,调试控制台和web检查器都是禁用的,因此需要启用它们。

希望这能帮上忙

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55752480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档