frank astin
frank astin

Reputation: 43

Jquery AJAX Failed to execute 'setRequestHeader'

A plain Jquery ajax request is throwing this error :

SyntaxError: Failed to execute 'setRequestHeader' … }↵}' is not a valid HTTP header field value.

$.ajax({url : '/ajax'})

I have tested this with a normal javascript xmlhttp request and it works fine. Any ideas what is going on?

Upvotes: 2

Views: 4145

Answers (1)

user5056311
user5056311

Reputation: 169

you're sending setrequestheader as a header key, so your syntax is wrong. if you're using $.get(); you need to use $.ajaxSetup({}); and include the below method, or to avoid using a global setup for all your further ajax calls use $.ajax({}); and include your ajax settings within that specific wrapper.

you can set your request header with beforesend method of jquery ajax like this:

    beforeSend: function (xhr) {xhr.setRequestHeader('Content-Type', 'bla bla');}

Upvotes: 2

Related Questions