html 使用JavaScript查询Apple的服务器,检查AirPod商店的可用性。使用Textastic创建,内置网络效果很好

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 使用JavaScript查询Apple的服务器,检查AirPod商店的可用性。使用Textastic创建,内置网络效果很好相关的知识,希望对你有一定的参考价值。

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
    <title>Check AirPod availability in Apple Stores</title>
    <style>
        body {
            font-size: 12px;
            font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
            padding: 1em;
        }
        
        table {
            max-width: 100%;
            width: 500px;
            text-align: left;
            border-collapse: collapse;
            border: 1px solid #69c;
            margin-bottom: 1em;
        }
        
        table th {
            padding: .5em;
            font-weight: normal;
            font-size: 1.1em;
            color: #039;
            border-bottom: 1px solid #69c;
        }
        
        table td {
            padding: .5em;
            color: #669;
            font-size: 1em;
        }
    </style>
    <!-- using jQuery to easily make JSONP calls -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
        function insertHeaderRow(thead, text) {
            var row = thead.insertRow(-1);
            var th = document.createElement("th");
            th.innerHTML = text;
            th.colSpan = 2;
            row.appendChild(th);
        }

        function insertRow(tbody, text1, text2) {
            var row = tbody.insertRow(-1);

            var cell1 = row.insertCell(0);
            cell1.innerHTML = text1;
            var cell2 = row.insertCell(1);
            cell2.innerHTML = text2;
        }


        function checkZipCode(country, zip, partnum) {
            var table = document.createElement("table");
            document.body.appendChild(table);

            var header = table.createTHead();
            var tbody = table.createTBody();

            insertHeaderRow(header, "Checking AirPods for " + country.toUpperCase() + ", " + zip);

            // the JSON url to get
            // see http://brianbrunner.com/2016/09/20/iphone-pickup.html for details
            var url = "http://www.apple.com/" + country + "/shop/retail/pickup-message?parts.0=" + partnum + "&location=" + zip;
            // use YQL (Yahoo! Query Language) to circumvent JavaScript cross origin limitations
            var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + url + '"') + '&format=json&callback=?';

            //console.log(url);

            // use JQuery to make a JSONP call to YQL
            $.getJSON(yql, function(data) {
                var json = data.query.results.body.content;
                var obj = JSON.parse(json);

                obj.body.stores.forEach(function(store, index) {
                    var availability = store.partsAvailability[partnum].storePickupQuote;

                    insertRow(tbody, store.city, availability);
                });
            });
        }


        function checkAvailability() {
            checkZipCode("us", "98112", "MMEF2AM/A");
            checkZipCode("de", "60313", "MMEF2ZM/A");
        }
    </script>
</head>

<body onload="checkAvailability()">
</body>

</html>

以上是关于html 使用JavaScript查询Apple的服务器,检查AirPod商店的可用性。使用Textastic创建,内置网络效果很好的主要内容,如果未能解决你的问题,请参考以下文章

在 HTML5 视频标签中使用 QuickTime/JavaScript API

如何在猫鼬中执行“每个”查询

响应式设计损坏(仅在 iPhone 上)- 可以使用 javascript 强制执行媒体查询吗?

通过 Javascript 检测 Apple Watch(例如,用户代理)

JavaScript编程题

如何使用 JavaScript 从 Apple Pay 获取与 Apple Pay 帐户关联的用户电子邮件地址