标题:AJAX调用REST API返回NULL
只看楼主
janba
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-1-30
 问题点数:0 回复次数:0 
AJAX调用REST API返回NULL
各位大侠,小弟最近遇到一个难题,请各位不吝帮忙,先谢过,问题如下:

我可以通过IE8浏览器调用以下API
# Request
GET https://www.
# Response
{
    "date": "1410431279",
    "ticker": {
        "buy": "33.15",
        "high": "34.15",
        "last": "33.15",
        "low": "32.05",
        "sell": "33.16",
        "vol": "10532696.39199642"
    }
}
这个API还有以下的说明:All requests go over https protocol, The field 'contentType' in request header should be: 'application/x-www-form-urlencoded'. The root url is: https://www.

然后我在JS中想通过AJAX调用,缺发现跳出的信息窗是"用户名:null",源代码如下:
 <script src="Js/jquery-1.4.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnSave").click(
               function () {
                $.ajax({
                    type: "get",
                    contentType: "application/x-www-form-urlencoded",
                    dataType: "json",
                    url: "https://www.,
                    success: function (data) {
                        alert("用户名:" + data);
                    },
                    error: function (error) {
                        alert("出错:" + error.responseText);
                    }
                });
            }
            );

        })
    </script>
搜索更多相关主题的帖子: 浏览器 request Request protocol field 
2016-01-30 22:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-461486-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.276272 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved