如何调用ASP.NET web api [英] How to call ASP.NET web api
问题描述
你好朋友,
我创建了网站,我想将Auth0.com(第三方)整合到我的应用程序中。问题是我在asp.net中创建了一个web api和我当请求更改密码时,想要在auth0内调用api。
有没有人知道这一点。请帮助我。
我尝试过:
1)$。ajax({
url:'http:/ / localhost:2615 / api / data / userdata / updatepass',
方法:'POST',
数据:{
email:email ,
Motdepasse:newPassword
}
})。然后(函数(数据){
返回回调(数据);
},function(){
返回回调(到达服务器端点时出错);
});
2)
var newName ='John Smith',
xhr = new XMLHttpRequest();
xhr.open('POST','http:// localhost:2615 / api / data / userdata / updatepass');
xhr。 setRequestHeader('Content-Type','application / x-www-form-urlencoded');
xhr.onload = function(){
if(xhr.status === 200&& xhr.responseText!== newName){
alert('出错了。名字现在是'+ xhr.responseText);
}
否则(xhr.status!== 200){
alert('请求失败。'+ xhr.status的返回状态);
}
};
xhr.send(encodeURI('name ='+ newName));
上面的操作我试过但没有解决方案。
Hello friends,
I had created website and i want to integrate Auth0.com (third party) into my application.The problem is that i had created one web api in asp.net and i want to call api inside auth0 when request goes to change password.
Is there any one who knows that very well.Please help me.
What I have tried:
1)$.ajax({
url: 'http://localhost:2615/api/data/userdata/updatepass',
method: 'POST',
data: {
email:email,
Motdepasse:newPassword
}
}).then(function(data) {
return callback(data);
}, function() {
return callback("Error reaching server endpoint");
});
2)
var newName = 'John Smith',
xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:2615/api/data/userdata/updatepass');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200 && xhr.responseText !== newName) {
alert('Something went wrong. Name is now ' + xhr.responseText);
}
else if (xhr.status !== 200) {
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send(encodeURI('name=' + newName));
Above opsition i had tried but no solution.
推荐答案
.ajax({
url:'http:// localhost:2615 / api / data / userdata / updatepass',
方法:'POST',
数据:{
电子邮件:电子邮件,
Motdepasse:newPassword
}
})。然后(函数(数据){
返回回调(数据);
},函数(){
返回回调(到达服务器端点时出错);
});
2)
var newName ='Jo史密斯',
xhr =新的XMLHttpRequest();
xhr.open('POST','http:// localhost: 2615 / api / data / userdata / updatepass');
xhr.setRequestHeader('Content-Type','application / x-www-form-urlencoded');
xhr.onload = function(){
if(xhr.status === 200&& xhr.responseText!== newName){
alert('出错了。名字现在是'+ xhr.responseText);
}
否则(xhr.status!== 200){
alert('请求失败。'+ xhr.status的返回状态);
}
};
xhr.send(encodeURI('name ='+ newName));
上面的操作我试过但没有解决方案。
.ajax({
url: 'http://localhost:2615/api/data/userdata/updatepass',
method: 'POST',
data: {
email:email,
Motdepasse:newPassword
}
}).then(function(data) {
return callback(data);
}, function() {
return callback("Error reaching server endpoint");
});
2)
var newName = 'John Smith',
xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:2615/api/data/userdata/updatepass');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200 && xhr.responseText !== newName) {
alert('Something went wrong. Name is now ' + xhr.responseText);
}
else if (xhr.status !== 200) {
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send(encodeURI('name=' + newName));
Above opsition i had tried but no solution.
})。then(function(data){应该由Success替换:function(data)
}).then(function(data){ should be replace by Success: function(data)
Correct format of
的正确格式
ajax如下:
ajax is below:
这篇关于如何调用ASP.NET web api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!