简体   繁体   English

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

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

The current project I'm working on requires me to talk with the windows live API. 我正在处理的当前项目要求我与windows live API交谈。 I use an AJAX request to receive a JSON object with the user details. 我使用AJAX请求来接收带有用户详细信息的JSON对象。 How ever I keep getting this error: Failed to load resource: the server responded with a status of 415 (Unsupported Media Type) 我怎么一直收到这个错误: 无法加载资源:服务器响应状态为415(不支持的媒体类型)

My first idea was to add a "&callback=?" 我的第一个想法是添加一个“&callback =?” the url. 网址。 But then I get "Uncaught SyntaxError: Unexpected token :" in the JSON response. 但后来我在JSON响应中得到“Uncaught SyntaxError:Unexpected token:”

I've been searching on how I could fix the error(s). 我一直在寻找如何解决错误。 But found no working solution for both errors. 但是找不到两种错误的可行解决方案。 On top if that I'm quite unsure which error I should try solving (status 415 or unexpected token). 最重要的是,如果我不确定我应该尝试解决哪个错误(状态415或意外令牌)。 Anything pointing me in the right direction would be greatly appreciated! 任何指向我正确方向的东西都将非常感激!

$.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');
        }
    });

thanks in advance 提前致谢

Have you tried setting 你试过设置吗?

dataType: 'jsonp',

and the "&callback=?" "&callback=?" in the url? 在网址? You are calling a server on another domain and so you must set jsonp as dataType 您正在另一个域上调用服务器,因此您必须将jsonp设置为dataType

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

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