1

I am making request calls using $.ajax, with post.

The problem is, the post variables are becoming part of the request header, which is causing error when our software is using it to check signatures using the request.

$.ajax({
    url: oauth.signed_url,
    type: "POST",
    beforeSend: function(jqXHR, settings) {},
    dataType: "json",
    headers: oauth.header,
    data: {
        description: "TESTME2222"
    },
    success: function(data) {
        //console.log(data);
    }
});

This line: headers: oauth.header, is the header I want to use, but apparently it appends to the existing header. Is there any way to replace headers?

EDIT:

I understand I can modify the headers using beforeSend function, but the problem is, i want to get rid of some of them. From what I know, can't really do that using the jqXHR object. It would be easier for me if i just replace the whole thing.

tpae
  • 6,286
  • 2
  • 37
  • 64
  • 1
    I can understand a newbie who doesn't know how to format to not indent code. But I would expect a >1k reputation user to indent his code properly. – Madara's Ghost Nov 05 '11 at 20:41
  • From documentation about headers in ajax with jQuery: This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function. – Charles Smith Nov 05 '11 at 20:42
  • thanks for formatting my code. i just wrote it up really quickly as an example. sorry for the difficulties. +1 to you. – tpae Nov 05 '11 at 20:44
  • @CharlesSmith I have some request headers i want to get rid of, but then again, it would be easier if i can just replace the whole thing. – tpae Nov 05 '11 at 20:44
  • @tpae I'd look here – Charles Smith Nov 05 '11 at 20:47
  • @CharlesSmith I was looking at that earlier, but it pretty much says I can't do it without editing the core jquery, which I do not want to do. I was thinking if there might be an easier way? – tpae Nov 05 '11 at 20:54
  • I don't think you can. For one, it triggers a security error to set (and similarly, clear) certain headers, such as `UserAgent`. – Eric Nov 05 '11 at 21:17

1 Answers1

0

I've modified the oauth server to accept only certain parameters, excluding other miscellaneous parameters passed through jQuery.

tpae
  • 6,286
  • 2
  • 37
  • 64