setting accept-language in header

11,527

The issue is because you need to wrap the header names in quotes otherwise the - is interpreted by JS as a subtraction operator - hence why it is unexpected within the object. Try this:

headers: {
    'Accept': 'application/json', 
    'From': '[email protected]', 
    'Accept-Language': 'sv'
}
Share:
11,527
Cyrus Zei
Author by

Cyrus Zei

Updated on July 01, 2022

Comments

  • Cyrus Zei
    Cyrus Zei almost 2 years

    I am using an API and in the GET request it wants this:

    Accept: application/json
    Accept-Language: sv
    From: [email protected]
    

    My code looks like this:

    var full_url = "http://api.arbetsformedlingen.se/af/v0/platsannonser/matchning?nyckelord=it";
    $.ajax({
        typ: 'GET',
        url: full_url,
        dataType: 'json',
        headers: {
            Accept: 'application/json', 
            from: '[email protected]', 
            accept-language: 'sv'
        }
    });
    

    When I add the accept-language: sv I get this:

    Unexpected token -

    What am I doing wrong here? The API is saying that it needs to have those 3 parameters for it to work.