June 5th, 2012 11:00 AM
#1
AJAX call not including headers I specify
I have a javascript/jQuery function:
function getResponse() {
var currentDate = new Date();
var sendMessage = JSON.stringify({
SendTimestamp: currentDate,
Message: "Message 1"
});
$.ajax({
type: "POST",
url: "http://L45723:1802",
data: sendMessage,
headers: {
Accept: "text/x-json",
"Authorization": "Basic " + $.base64.encode("server:server123")
},
contentType: "text/x-json",
success: function (data) {
$('#_receivedMsgLabel').append(data.Message + '<br/>');
alert("ajax.success().");
getResponse();
},
async: true
});
}
However, when I check my server logs (and FireBug), this is the header I am sending in my request:
Host : l45723:1802
User-Agent : Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language : en-us,en;q=0.5
Accept-Encoding : gzip, deflate
Connection : keep-alive
Origin : http://l45723
Access-Control-Request-Method : POST
Access-Control-Request-Headers : authorization,content-type
Pragma : no-cache
Cache-Control : no-cache
Why isn't my authorization stuff included in the header?
June 5th, 2012 11:54 AM
#2
Re: AJAX call not including headers I specify
Tried changing to GET but still no luck:
$.ajax({
type: "GET",
url: "http://L45723:1802?test1=test2",
//dataType: "json",
async: true,
//data: sendMessage,
headers: {
Accept: "text/x-json",
"Authorization": "Basic " + $.base64.encode("server:server123")
},
success: function (data) {
$("#_receivedMsgLabel").append(data.Message + "<br/>");
alert("ajax.success().");
getResponse();
}
});
Firebug:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Access-Control-Request-He... authorization
Access-Control-Request-Me... GET
Connection keep-alive
Host l45723:1802
Origin http://l45723
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Server logs:
Request Url: /?test1=test2
Inside ParseInput(): ParseState.Headers
Parsing header: Host : l45723:1802
Inside ParseInput(): ParseState.Headers
Parsing header: User-Agent : Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Inside ParseInput(): ParseState.Headers
Parsing header: Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Inside ParseInput(): ParseState.Headers
Parsing header: Accept-Language : en-us,en;q=0.5
Inside ParseInput(): ParseState.Headers
Parsing header: Accept-Encoding : gzip, deflate
Inside ParseInput(): ParseState.Headers
Parsing header: Connection : keep-alive
Inside ParseInput(): ParseState.Headers
Parsing header: Origin : http://l45723
Inside ParseInput(): ParseState.Headers
Parsing header: Access-Control-Request-Method : GET
Inside ParseInput(): ParseState.Headers
Parsing header: Access-Control-Request-Headers : authorization
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks