jquery json不返回任何值/响应

时间:2010-11-16 07:18:34

标签: jquery json

我正在使用getJSON来获取页面返回的json值, 但该功能没有回复..

<html>
<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        alert ("dfdfad");
        function sam()
        {
            alert("entere");
            $.getJSON(
                'https://test.httpapi.com/api/domains/available.json?',
                {
                    'auth-userid':'234343',
                    'auth-password':'xxxxxxxx',
                    'domain-name':'yyyyy',
                    'tlds':'com',
                    'tlds':'info',
                    'suggest-alternative':'true'
                },
                function(json,textStatus,xhr) {
                    alert ("inside the fun");
                    alert("JSON Data: " + json);
                }
            );
            alert("finish");
        }
    </script>
</head>
<body>

<div>
    <h2>Let AJAX change this text</h2>
</div>
<button onclick=sam();>Change Content</button>
</body>
</html>

当我在浏览器中使用以下网址时,它会返回与json完全相同的值..

以下网址可能无法在其他网址上运行,因为它需要注册ip才能获得响应。我确信我的网址已经注册并正常工作

https://test.httpapi.com/api/domains/available.json?auth-userid=2343432&auth-password=xxxxxx&domain-name=testhiox&tlds=com&tlds=info&tlds=org&suggest-alternative=true 

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

您可以使用Fiddler来检查对您的请求的HTTP响应。我尝试使用下面的代码,但得到了504 - 连接失败错误。

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
    <script type="text/javascript">
        var samNS = samNS || {};

        $(function () {
            alert ("dfdfad");
            samNS.sam = function ()
            {
                alert("entere");
                $.getJSON(
                    'https://test.httpapi.com/api/domains/available.json',
                    {
                        'auth-userid':'232323',
                        'auth-password':'xxxx',
                        'domain-name':'yyyy',
                        'tlds':'com',
                        'tlds':'info',
                        'suggest-alternative':'true'
                    },
                    function(json, textStatus, xhr) {
                        alert ("inside the fun");
                        alert("JSON Data: " + json);
                    }
                );

                alert("finish");
            }
        });

    </script>
</head>
<body>

<div>
    <h2>Let AJAX change this text</h2>
</div>
<button onclick="samNS.sam();">Change Content</button>
</body>
</html>
相关问题