Search code examples
javascriptjqueryajaxjsonlive

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. 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.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


Solution

  • 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