发送请求时 HTML 中的 JavaScript“错误”

问题描述

因此,我对此代码进行了更新,以解决在另一个问题中指出的一些问题。该函数运行,但返回 {"readyState":0,"status":0,"statusText":"error"}。我从 $.getJSON 切换到 $.ajax 以便我可以发送标头以希望修复错误,但它仍然给我同样的错误,没有太多细节。

<HTML>
<head>
    <title>Ecobee API PIN TEST</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        $(document).ready(function PINCode() {
            
            apiKey = 'kmkbJCrEUbMBpO2I6E90QeYcueAz1p00'
            
            // set all apiKey inputs to have apiKey value entered
            $(".apiKey").each(function() {
                $(this).val(apiKey);
            });
            
            var url = 'https://api.ecobee.com/authorize?response_type=ecobeePin&client_id=' + apiKey + '&scope=smartWrite';
            $.ajax({
                dataType: "json",url: url,headers: { 'Access-Control-Allow-Origin': '*' },success: function(data) {
                    $("#authCode").val(data.code);
                    alert("JSON Ran");
                    var response = JSON.stringify(data,null,4);
                    $('#response1').html(response);
                }
            })
//            $.getJSON(url,function(data) {
//                // set authCode to be code attribute of response
//                $("#authCode").val(data.code);
//                alert("JSON Ran")
//                var response = JSON.stringify(data,4);
//                $('#response1').html(response);
//            })
            .fail(function(jqXHR,textStatus) {
                $('#response1').html("The following error was returned: <br><br>" + JSON.stringify(jqXHR) + "<p>Please Contact <b>M2 AV Consulting</b> at <a href=mailto:support@m2avc.com?subject='EcobeePINSupport'>support@m2avc.com</a>")
                console.log(textStatus);
            });
        })
    </script>
    <pre id="response1" class="code-json">(Response JSON will appear here...I hope.)</pre>
</body>
</HTML>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...