Created
January 1, 2012 14:02
-
-
Save pithyless/1547408 to your computer and use it in GitHub Desktop.
jQuery set Headers for $.ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery Headers support for $.ajax | |
$.ajax({ | |
beforeSend: function(xhrObj){ | |
xhrObj.setRequestHeader("Content-Type","application/json"); | |
xhrObj.setRequestHeader("Accept","application/json"); | |
} | |
type: "POST", | |
url: "/article", | |
processData: false, | |
data: jsonData, | |
dataType: "json", | |
success: function(json){ | |
do something... | |
} | |
}); |
I'm trying this:
$.ajax({
headers: {
Accept : "text/javascript; charset=utf-8",
"Content-Type": "text/javascript; charset=utf-8"
},
type: "GET", url: rootURL, dataType: "jsonp",
beforeSend: function(xhr){
xhr.setRequestHeader('Access-Control-Allow-origin', 'true');
},
//jsonp: false,
//jsonpCallback: 'eval',
success: function(data) {
console.log(data);
},
error: function(jqXHR, msg, erro){
console.log(erro);
}
});
But the request is going:
Accept: /
HELP!!
hello i think only the server can set 'Access-Control-Allow-origin' @lazaropj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For me it work like this :)