BR
asked on
adding header to posting function in JQuery?
Dear Experts,
I'm new to JQuery, I'd like to post some data to a page but I need to add header information.
How can I add this header to below code?
headers: ['Content-Type: application/json','Authori zation: Autho xxxxxxx'],
thank you
I'm new to JQuery, I'd like to post some data to a page but I need to add header information.
How can I add this header to below code?
headers: ['Content-Type: application/json','Authori
thank you
<script type="text/javascript">
$(document).ready(function () {
$('#ajaxBtn').click(function(){
$.post('theURLtoPOST', // url
{"ProductId":"1","Id":"54"},
function(data, status, jqXHR) {// success callback
$('p').append('status: ' + status + ', data: ' + data);
});
});
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what about :
headers: '["Content-Type":"applicat ion/json", "Authoriza tion":"Aut ho xxxxxxx"]'
headers: '["Content-Type":"applicat
ASKER
Dear leakim971,
thank you so much for your help,
it posts the data but the header is not working. I do not know why?
thank you so much for your help,
it posts the data but the header is not working. I do not know why?
<script type="text/javascript">
$(document).ready(function () {
$.ajaxSetup({
headers: {'Content-Type': 'application/json','Authorization': 'Bearer TOKEN' }
});
$('#ajaxBtn').click(function() {
$.post('https://......', {"ProductId":"1","VirId":"54"}, function(data, status, jqXHR) {// success callback
$('p').append('status: ' + status + ', data: ' + data);
});
});
});
</script>
ASKER
Dear leakim971,
thank you
I think this problem is “No 'Access-Control-Allow-Orig in'
I will check this
thank you
thank you
I think this problem is “No 'Access-Control-Allow-Orig
I will check this
thank you
ASKER
it is perfect, however, I need to write the hedader information just as it is
headers: ['Content-Type: application/json','Authori
and it doesn't seems to work.
what should i do?
Normaly with php, I post it like this
$headers = ['Content-Type: application/json','Authori
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);