繁体   English   中英

服务器响应的Ajax / JSON状态为415(不支持的媒体类型)

[英]Ajax/JSON the server responded with a status of 415 (Unsupported Media Type)

我正在处理的当前项目要求我与windows live API交谈。 我使用AJAX请求来接收带有用户详细信息的JSON对象。 我怎么一直收到这个错误: 无法加载资源:服务器响应状态为415(不支持的媒体类型)

我的第一个想法是添加一个“&callback =?” 网址。 但后来我在JSON响应中得到“Uncaught SyntaxError:Unexpected token:”

我一直在寻找如何解决错误。 但是找不到两种错误的可行解决方案。 最重要的是,如果我不确定我应该尝试解决哪个错误(状态415或意外令牌)。 任何指向我正确方向的东西都将非常感激!

$.ajax({
        url: "https://apis.live.net/v5.0/me?access_token=" + localStorage.getItem('Live_token'),
        dataType: 'json',
        type : 'GET',
        contentType: "application/json;",
        async: false,
        success : function(data) {
            var id = data.id,
            fname = data.last_name,
            email = data.emails.preferred;//TODO preferred or account?
            alert(id + '|' + fname + '|' + email);
            localStorage.setItem('Live_verifier', id + '|' + fname + '|' + email);
        },
        error : function(data) {
            localStorage.removeItem('Live_token');
        }
    });

提前致谢

你试过设置吗?

dataType: 'jsonp',

"&callback=?" 在网址? 您正在另一个域上调用服务器,因此您必须将jsonp设置为dataType

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM