Load url with $ .ajax and token usage

-1
O código seguinte não carrega url. O que está errado?



    var token = "XfdfdffddfdfdfferrrrrrrrrrreeeeeeeeeeJ777K";
    var url = "https://producao-talcoisa.com/api/Produto/PesquisarConteudo/";

    $.ajax({

        url : url,
        type : 'GET',
        contentType : "application/json",
        beforeSend: token,
        error : onError,
        success : onSuccess

    });




tokenSession =  null;

var setHeader = function(xhr) {
    xhr.setRequestHeader('tokenApp', token);
    if (token.tokenSession != null) {
        xhr.setRequestHeader('token', token.tokenSession);
    }
};



    function onSuccess() {

        console.log("sucesso");
        // ToastMessage.showMessage("Sucesso");

    }


    function onError() {
        console.log("Erro");
        // ToastMessage.showMessage("Erro");
    }
    
asked by anonymous 16.01.2015 / 12:56

1 answer

0

Your request is probably POST , and it does not make sense for you to pass a string to beforeSend

Try this:

$.ajax({

    url : url,
    type : 'POST',
    contentType : "application/json",
    data: {token:token},
    error : onError,
    success : onSuccess

});
    
16.01.2015 / 13:31