我正在大学的毕业项目中使用playframework,并且在路由DELETE或PUT方法时遇到了问题。当我请求DELETE或PUT方法时,会出现以下错误信息:
我的JQuery ajax调用如下:[info] play.api.Play - 应用程序已启动 (Dev) [debug] a.ErrorHandler - onClientError: statusCode = 404, uri = /Rest/deleteCity, message ="
$("#scalaDelete").click(function(){
$("#result").empty();
$.ajax({
url: "http://localhost:9000/Rest/deleteCity",
method: "DELETE",
data: {city: "Alvorada"},
dataType: "json",
success: function(result){
$("#result").append("Result: "+result.Result);
},
error: function (request, status, error) {
alert(status);
}
});
});
我的路由播放路径:
DELETE /Rest/deleteCity controllers.RestController.deleteCity()
我的控制器方法:
case class UserDelete(city:String)
class RestController @Inject()(db: Database, cc: ControllerComponents) extends AbstractController(cc) {
val userDeleteForm = Form(
mapping(
"city" -> text
)(UserDelete.apply)(UserDelete.unapply)
)
def deleteCity = Action{ implicit request=>
val userPar = userDeleteForm.bindFromRequest.get
//DatabaseDelete
Ok(jsonResult)
}
}
我已经在Chrome中激活了跨域,我使用了一个CORS扩展程序。
谢谢您的帮助