admin管理员组

文章数量:1336632

The current project I'm working on requires me to talk with the windows live API. I use an AJAX request to receive a JSON object with the user details. How ever I keep getting this error: Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)

My first idea was to add a "&callback=?" the url. But then I get "Uncaught SyntaxError: Unexpected token :" in the JSON response.

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). Anything pointing me in the right direction would be greatly appreciated!

$.ajax({
        url: ".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

The current project I'm working on requires me to talk with the windows live API. I use an AJAX request to receive a JSON object with the user details. How ever I keep getting this error: Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)

My first idea was to add a "&callback=?" the url. But then I get "Uncaught SyntaxError: Unexpected token :" in the JSON response.

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). Anything pointing me in the right direction would be greatly appreciated!

$.ajax({
        url: "https://apis.live/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

Share Improve this question asked Mar 16, 2012 at 13:29 ReinardReinard 3,65410 gold badges44 silver badges61 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

Have you tried setting

dataType: 'jsonp',

and the "&callback=?" in the url? You are calling a server on another domain and so you must set jsonp as dataType

本文标签: javascriptAjaxJSON the server responded with a status of 415 (Unsupported Media Type)Stack Overflow