当我在提交表单后通过ajax调用它时,错误显示为"HTTP错误405.0-不允许使用方法". [英] When I call it through ajax after submitting form it shows error as "HTTP error 405.0 - method not allowed"
本文介绍了当我在提交表单后通过ajax调用它时,错误显示为"HTTP错误405.0-不允许使用方法".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
报价:
我遇到一个有关Change pwd的Web api的问题,它在提琴手中正常工作,但是当我在提交后通过ajax调用它时表单显示错误为"HTTP错误405.0-不允许方法 d"
I have an issue regarding web api for Change pwd it is working properly in fiddler but when i call it through ajax after submitting form it shows error as "HTTP Error 405.0 - Method Not Allowed"
我尝试过的事情:
What I have tried:
<pre>// Cotroller
[HttpPut]
public HttpResponseMessage Put([FromUri]string oldPwd, [FromBody]Hotel_Login Hotel_Login)
{
using (Hotel_ShowEntities entities = new Hotel_ShowEntities())
{
try
{
var entity = entities.Hotel_Login.FirstOrDefault(e => e.Password == oldPwd);
if (entity == null)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer with that Password=" + oldPwd.ToString() + "not found");
}
else
{
entity.Password = Hotel_Login.Password;
entities.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK, entity);
}
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
}
//Ajax call
$(document).ready(function () {
$("#btnSubmit").click(function () {
var CurrentPwd = $("#CurrPwd").val();
var Newpwd = $("#NewPwd").val();
console.log(Newpwd);
$.ajax({
type: "Put",
url: "http://localhost:16580/api/ChangeForgetPass/Put?oldPwd=" + CurrentPwd,
contentType: "application/json",
dataType: "json",
processData: true,
data: ''{"Password":"'' + Newpwd + ''"}'',
success: function (s) {
alert("Password Changed successfully");
},
});
});
});
推荐答案
(document).ready(function(){
(document).ready(function () {
(#btnSubmit").click(功能 () { var CurrentPwd =
("#btnSubmit").click(function () { var CurrentPwd =
(#CurrPwd").val(); var Newpwd =
("#CurrPwd").val(); var Newpwd =
这篇关于当我在提交表单后通过ajax调用它时,错误显示为"HTTP错误405.0-不允许使用方法".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文