@{ ViewBag.Title = "测试页"; Layout = "~/Views/Shared/_LayoutPage.cshtml"; } <div> 上传文件 <input type="file" id="file" /> <br /> <input type="button" id="upload" value="上传文件" /> </div> <div style="margin:50px 0;"> <form action="../api/File/DownloadFile" method="get" id="form"> 下载文件 <input type="text" id="name" name="fileName" placeholder="文件名,例如:xxx.doc" /> </form> <input type="button" id="download" value="下载文件" /> </div> <div> <h2>权限测试</h2> <input type="button" value="查询" class="Query" /> <input type="button" value="修改" class="Update" /> <input type="button" value="删除" class="Delete" /> <input type="button" value="新增" class="Insert" /> <input type="button" value="上传" class="Upload" /> <input type="button" value="下载" class="Download" /> </div> <script src="~/Scripts/jquery-3.4.1.js"></script> <script src="~/Scripts/helper.js"></script> <script> //上传 $("#upload").click(function () { var formData = new FormData(); var file = document.getElementById("file").files[0]; formData.append("fileInfo", file); $.ajax({ url: "../api/File/UploadFile", type: "POST", data: formData, contentType: false,//必须false才会自动加上正确的Content-Type processData: false,//必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理 success: function (data) { alert(data); }, error: function (data) { alert("上传失败!"); } }); }); //下载 $("#download").click(function () { var form = $("#form"); form.submit(); }); function code2Session() { $.get("http://localhost:44354/api/UserInfo/code2Session", { js_code: "093BOOFa12rHrz0w7pHa18TRmI0BOOFQ" }, function (data) { }); } function Add() { $.post("http://localhost:44354/api/UserInfo/Add", { UserName: "张三", Phone: "15065876998" }, function (data) { }); } function InsertBulk() { $.post("http://localhost:44354/api/UserInfo/InsertBulk", null, function (data) { }); } function Delete() { $.post("http://localhost:44354/api/UserInfo/Delete", { UserID: "1" }, function (data) { }); } function DeleteBatch() { var _parameter = [{ UserID: "2", UserName: "222" }, { UserID: "3", UserName: "222" }]; $.ajax({ type: "Post", contentType: "application/json", url: "http://localhost:44354/api/UserInfo/DeleteBatch", data: JSON.stringify(_parameter) }); } function Insert() { $.post("http://localhost:44354/api/UserInfo/Insert", { UserName: "王五", Phone: "15065876998" }, function (data) { }); } function Query() { $.get("http://localhost:44354/api/UserInfo/Query", { UserName: "张三" }, function (data) { }); } function Get() { $.get("http://localhost:44354/api/UserInfo/Get", { id: 4 }, function (data) { }); } function GetListAll() { $.get("http://localhost:44354/api/UserInfo/GetListAll", null, function (data) { }); } function GetList() { $.post("http://localhost:44354/api/UserInfo/GetList", { UserID: "5" }, function (data) { }); } function GetPageListForSQL() { var _parameter = [{ UserID: "2" }, { UserID: "3" }]; $.ajax({ type: "Post", contentType: "application/json", url: "http://localhost:44354/api/UserInfo/GetPageListForSQL", data: null }); } function GetPage() { var _parameter = { ID: 2 }; $.ajax({ type: "Post", contentType: "application/json", url: "http://localhost:44354/api/ServiceRecordReport/GetPage", data: JSON.stringify(_parameter) }); } //获取页面权限 function GetUserRolePageJurisdiction() { var _parameter = { UserID: 4, State: 0, PageURL: "index" }; $.post("http://localhost:44354/api/UserRoleJurisdiction/GetUserRolePageJurisdiction", _parameter, function (data) { var json = $.parseJSON(data.data); console.log(json.Jurisdiction); if (!objValidate.NotNull(json.Jurisdiction)) { alert("没有此页面权限!"); return; } if (json.Jurisdiction.indexOf("Insert") == -1) { $(".Insert").attr("disabled", "disabled"); } if (json.Jurisdiction.indexOf("Delete") == -1) { $(".Delete").attr("disabled", "disabled"); } if (json.Jurisdiction.indexOf("Update") == -1) { $(".Update").attr("disabled", "disabled"); } if (json.Jurisdiction.indexOf("Query") == -1) { $(".Query").attr("disabled", "disabled"); } if (json.Jurisdiction.indexOf("Upload") == -1) { $(".Upload").attr("disabled", "disabled"); } if (json.Jurisdiction.indexOf("Download") == -1) { $(".Download").attr("disabled", "disabled"); } }); } </script>