0

Here is my code.

$.ajax(this.url, {
        type: "GET",
        //dataType: "json",
        beforeSend: function (xhr) {
            xhr.setRequestHeader("x-token", token)
        },
        success: function (data) {
            console.log(data);
        },
        error: function(){
            console.log('error');
        } 
    });

I am not able to send ajax request by that code. I also try hearder: {"x-token": token}, In place of beforeSend: but its also not working for me.

code Zero
  • 115
  • 2
  • 8
  • 2
    Possible duplicate of [How can I add a custom HTTP header to ajax request with js or jQuery?](http://stackoverflow.com/questions/7686827/how-can-i-add-a-custom-http-header-to-ajax-request-with-js-or-jquery) – toskv Dec 06 '15 at 08:20
  • You must also explain what kind of error you are getting (if any), and what is happening in `this.url`? – Sina Dec 06 '15 at 08:33
  • I got console.log('error') on that, and in server the header comes with undefined value. And this.url get proper url its working fine for my post request. – code Zero Dec 06 '15 at 08:53

0 Answers0