admin管理员组文章数量:1026989
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>
Share
Improve this question
edited Mar 7, 2018 at 7:12
CommunityBot
11 silver badge
asked Mar 5, 2014 at 11:13
user3319135user3319135
912 gold badges3 silver badges11 bronze badges
10
- What is url: 'url_path'(It's a string) ? – Ishan Jain Commented Mar 5, 2014 at 11:15
-
What is
'url_path'
this is not the correct URL – Pavlo Commented Mar 5, 2014 at 11:15 - 2 The code you've shared will give us some idea of what you are sending to the server, but since we can't see the server side code - we have no idea what it is doing with the data to determine that you are not authorised. – Quentin Commented Mar 5, 2014 at 11:15
-
2
dataType: 'jsonp'
andtype:'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 - I have put my local path here , where i want to send this data and this data reaching perfectly. But its response which i am getting back is 401 error. – user3319135 Commented Mar 5, 2014 at 11:17
1 Answer
Reset to default 1From 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);
}
});
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>
Share
Improve this question
edited Mar 7, 2018 at 7:12
CommunityBot
11 silver badge
asked Mar 5, 2014 at 11:13
user3319135user3319135
912 gold badges3 silver badges11 bronze badges
10
- What is url: 'url_path'(It's a string) ? – Ishan Jain Commented Mar 5, 2014 at 11:15
-
What is
'url_path'
this is not the correct URL – Pavlo Commented Mar 5, 2014 at 11:15 - 2 The code you've shared will give us some idea of what you are sending to the server, but since we can't see the server side code - we have no idea what it is doing with the data to determine that you are not authorised. – Quentin Commented Mar 5, 2014 at 11:15
-
2
dataType: 'jsonp'
andtype:'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 - I have put my local path here , where i want to send this data and this data reaching perfectly. But its response which i am getting back is 401 error. – user3319135 Commented Mar 5, 2014 at 11:17
1 Answer
Reset to default 1From 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);
}
});
本文标签: javascriptWhy i am always getting 401 (Unauthorized) error in case jquery ajaxStack Overflow
版权声明:本文标题:javascript - Why i am always getting 401 (Unauthorized) error in case jquery ajax - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745660242a2161843.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论