I am using ajax in jquery. when i submit my value, I am getting this error every time. Please let me know where i am wrong?
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
url: 'url_path',
data: {
user : {
email : $('#email').val(),
password : $('#password').val()
} ,
vendor_identifier : '3231-43423-fdsdfs'
},
dataType: 'jsonp',
//method: 'POST',
type:'POST',
success: function(msg) {
var msg = $.parseJSON(msg);
console.log(msg);
}
});
});
});
</script>
I am using ajax in jquery. when i submit my value, I am getting this error every time. Please let me know where i am wrong?
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
url: 'url_path',
data: {
user : {
email : $('#email').val(),
password : $('#password').val()
} ,
vendor_identifier : '3231-43423-fdsdfs'
},
dataType: 'jsonp',
//method: 'POST',
type:'POST',
success: function(msg) {
var msg = $.parseJSON(msg);
console.log(msg);
}
});
});
});
</script>
'url_path'
this is not the correct URL
– Pavlo
Commented
Mar 5, 2014 at 11:15
dataType: 'jsonp'
and type:'POST'
are inpatible though. a JSON-P request is handled by generating a script element with a src attribute. That will always be a GET request.
– Quentin
Commented
Mar 5, 2014 at 11:16
From your example it seems that you are accessing some API which requires authentication through the email and password. The 401 Unauthorized
is simply saying that the remote server was for some reason unable to authenticate the user with the bination of email and password and possibly the vendor_identifier that you sent with the request.
Chances are that the API expects the username (email) and password in the form of Basic Authentication in the Authorization
HTTP header. If you are using JQuery >= 1.7.2 then it will create the Authorization
header for you.
see this question: How to use Basic Auth with jQuery and AJAX?
$(document).ready(function(){
$("button").click(function(){
$.ajax({
url: 'url_path',
data: {
user : {
email : $('#email').val(),
password : $('#password').val()
},
vendor_identifier : '3231-43423-fdsdfs'
},
username: $('#email').val(),
password: $('#password').val(),
dataType: 'jsonp',
success: function(msg) {
var msg = $.parseJSON(msg);
console.log(msg);
}
});