2016-09-30 129 views
0

任何人都可以请提供给我关于如何进行的输入。以下要求。网页表单和网页API整合

我有在VS专业2015年开发的Web应用程序,并有单独的Web API应用程序。到目前为止,现有的Web应用程序在3层架构中实现。现在我们想要使用不带3层架构的Web API调用来实现新页面。

首先,我想在我的web应用程序中创建一个基础结构/体系结构来调用Web API应用程序。这样所有新的页面请求都会通过这个基础结构/体系结构并调用Web API。

请帮助我提供宝贵意见/建议。

预先感谢您。

+0

使用角度JS或jQuery的通过AJAX来获取数据。服务器初始页面为静态html文件。 – zaitsman

回答

0

因为我们正在使用API除非有人愿意使用ReactJsAngularJs,否则不需要创建复杂的基础架构/体系结构。 对于他们来说,它甚至不是强制性的,但它可以让你保持代码清洁。您只需简单地使用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); 
    } 
});}); 

希望这有助于