因为我们正在使用API
除非有人愿意使用ReactJs
或AngularJs
,否则不需要创建复杂的基础架构/体系结构。 对于他们来说,它甚至不是强制性的,但它可以让你保持代码清洁。您只需简单地使用JavaScript调用API
即可 例如,您有一个API控制器方法并希望访问它。
产品
#region Get Method
// GET api/product
[Queryable]
[Route("Products")]
[Route("All")]
public HttpResponseMessage Get()
{
try
{
var products = _productServices.GetAllProducts();
var productEntities = products as List<ProductEntity> ?? products.ToList();
if (productEntities.Any())
{
return Request.CreateResponse(HttpStatusCode.OK, productEntities);
}
throw new ApiDataException(1000,"No Products Found",HttpStatusCode.NotFound);
}
catch (Exception)
{
throw;
}
}
#endregion
简单方法只需调用尊重方法从阿贾克斯这样
$(document).ready(function() {
var a = "Test";
$.ajax({
url: "v1/products/product/All",
type: "GET",
data: { a : a },
success: function (response) {
alert(response);
},
error: function (response) {
alert(response);
}
});});
希望这有助于
使用角度JS或jQuery的通过AJAX来获取数据。服务器初始页面为静态html文件。 – zaitsman