JQuery Ajax POST/GET 请求至 ASP.NET WebAPI
1.注意要点:ajax提交请求的dataType参数、contentType参数值应该分别为 dataType: 'json' 和 contentType: 'application/json;charset=utf-8' 不然会报js跨域啊,Method 错误啊 等等一些乱七八糟的js错误. 下面直接上代码: 前端代码: 1 <!DOCTYPE html> 2 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 5 <head runat="server"> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 <title></title> 8 <script src="js/jquery-2.2.3.min.js"></script> 9 <script type="text/javascript"> 10 $(function () { 11 $('#getData').click(function () { 12 $.ajax({ 13 url: 'http://localhost:58737/api/userInfo/getlist', 14 type: 'get', 15 dataType: 'json', 16