html ajax调用无法点击我的WebApi方法

时间:2016-12-16 19:07:33

标签: jquery ajax asp.net-web-api

我可以从POSTMAN中点击这个方法但是无法从简单的html页面点击以下是代码示例:

Jquery代码

var certificateNumber = $("#txtCertificateNumber").val();
$("#search-Certificate").click(function() {

  $.ajax({
    type: "GET",
    url: "http://localhost:8073/api/ami/CertificateDetails",
    data: certificateNumber,
    contentType: "application/json; charset=utf-8",
    cache: false,
    success: function(data) {
      $("#resultarea").text(data);
    }
  });
});

控制器API代码

[RoutePrefix("api/ami")]
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class APIController: ApiController {

   [HttpGet]
   [Route("CertificateDetails/{certificateNumber}")]
   public HttpResponseMessage GetHatcheryCertificateBy(string certificateNumber) {

   }

}

0 个答案:

没有答案