Microsoft为实现Ajax功能而开发的一组ASP.NET扩展。
首先我想说,虽然这是我第一次在这里发帖,但这些版块对我帮助很大。 话虽如此,我遇到了一个关于 AJAX 和脚本的奇怪问题。 你看,在...
我已经在 AJAX 方面工作了几个月,我看到 Ajax 请求如下, 向后台页面传递参数(PHP/ASP/HTML/TXT/XML...这里还能有什么?) 在服务器上做一些处理 ...
我想通过Ajax函数通过id commentList将数据加载到div中。我需要使用 Ajax 通过表单标记将数据发送到名为 CreateComment 的操作。创建评论后,我需要加载数据...
如何在 ASP.NET Web 表单应用程序中进行 AJAX 调用后显示成功或失败消息
我正在开发一个用 VB.Net 编写的 ASP.NET Webforms 项目。我想使用 Ajax 在后台代码中调用 Web 方法。按钮单击事件正确调用代码隐藏方法。然而
我有一个带有 DataList 的用户控件。我希望列表仅显示前 20 条记录,底部有一个“更多”链接。如果用户点击更多,则异步加载下面20多条记录...
我正在尝试使用 MVC4.Paging nuget 包实现 ASP.NET MVC 分页。 问题: 它可以在在线演示中运行,也可以在下载源代码中运行。但我无法找到为什么它不是
我正在尝试在asp.net中找到解决方案以实现数据分页,所以 1) 应用程序不必在每个页面索引更改时连接到数据库,以便检索整个集合或部分...
我正在一个项目中使用 ASP.NET MVC,并且我有一个数据表,该数据表在页面加载时工作正常,但是当我提交表单进行搜索时,它会返回正确的 json 响应,但事实并非如此
ASP .NET 6。托管在 Azure 上。 GetAllVehicles() Ajax 调用在 Visual Studio 2022 中有效,但在 Azure 上出错
$(文档).ready(函数() { $('#vehiclesTable').DataTable({ “处理”:真实, “服务器端&qu...</desc> <question vote="0"> <pre><code><script type="text/javascript"> $(document).ready(function () { $('#vehiclesTable').DataTable({ "processing": true, "serverSide": true, "ajax": { "url": "@Url.Action("GetAllVehicles", "Vehicles")", "type": "GET", "error": function (xhr, error, thrown) { console.log("Error: ", xhr.responseText); } }, "columns": [ { "data": "customerName" }, { "data": "year" }, { "data": "make" }, { "data": "model" }, { "data": "trim" }, { "data": "engineSize" }, { "data": "transmission" }, { "data": "transmissionType" }, { "data": "mileage" }, { "data": "id", "render": function (data, type, row) { return `<a href="/Vehicles/Details/${data}" class="btn btn-info">Details</a> <a href="/Vehicles/Edit/${data}" class="btn btn-warning">Edit</a> <a href="/Vehicles/Delete/${data}" class="btn btn-danger">Delete</a>`; }, "orderable": false } ], "order": [[0, "asc"]] }); }); </script> <- script in index.html [HttpGet] public async Task<IActionResult> GetAllVehicles() { var draw = HttpContext.Request.Query["draw"].FirstOrDefault(); var start = Request.Query["start"].FirstOrDefault(); var length = Request.Query["length"].FirstOrDefault(); var sortColumn = Request.Query["columns[" + Request.Query["order[0][column]"].FirstOrDefault() + "][data]"].FirstOrDefault(); var sortColumnDirection = Request.Query["order[0][dir]"].FirstOrDefault(); var searchValue = Request.Query["search[value]"].FirstOrDefault(); int pageSize = length != null ? Convert.ToInt32(length) : 0; int skip = start != null ? Convert.ToInt32(start) : 0; int recordsTotal = 0; // Fetch all data var vehiclesData = _context.Vehicles .Include(j => j.Customer) .Select(j => new { j.Id, CustomerName = j.Customer.FirstName + " " + j.Customer.LastName, j.Year, j.Make, j.Model, j.Trim, j.EngineSize, j.Transmission, j.TransmissionType, j.Mileage }); // Search if (!string.IsNullOrEmpty(searchValue)) { vehiclesData = vehiclesData.Where(j => j.CustomerName.Contains(searchValue) || j.Year.ToString().Contains(searchValue) || j.Make.Contains(searchValue) || j.Model.Contains(searchValue) || j.Trim.Contains(searchValue) || j.EngineSize.Contains(searchValue) || j.Transmission.Contains(searchValue) || j.TransmissionType.Contains(searchValue) || j.Mileage.Contains(searchValue) ); } // Sorting if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection))) { var sortExpression = $"{sortColumn} {sortColumnDirection}"; vehiclesData = vehiclesData.OrderBy(sortExpression); } // Total number of rows count recordsTotal = vehiclesData.Count(); // Paging var data = vehiclesData.Skip(skip).Take(pageSize).ToList(); // Returning Json Data var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data.Select(v => new { customerName = v.CustomerName, year = v.Year, make = v.Make, model = v.Model, trim = v.Trim, engineSize = v.EngineSize, transmission = v.Transmission, transmissionType = v.TransmissionType, mileage = v.Mileage, id = v.Id }) }; return Ok(jsonData); } </code></pre> <p><- VehiclesController GetAllVehicles()</p> <p>当我在本地运行它时,效果非常好。当我将其推送到 Azure 时,它就崩溃了。</p> <p>我尝试了不同的调用、路由,每个更改都在本地工作,但在推送到 Azure 时就崩溃了。我有另一个控制器,它的调用几乎相同,只是数据不同,并且工作完美。</p> </question> <answer tick="false" vote="0"> <p>使用当前代码,网址如下:</p> <p><strong>本地:</strong></p> <pre><code>https://localhost:port/Vehicles/GetAllVehicles?draw=1&columns%5B0%5D%5Bdata%5D=customerName&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=year&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=make&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=model&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=trim&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=engineSize&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=transmission&columns%5B6%5D%5Bname%5D=&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=transmissionType&columns%5B7%5D%5Bname%5D=&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=true&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B8%5D%5Bdata%5D=mileage&columns%5B8%5D%5Bname%5D=&columns%5B8%5D%5Bsearchable%5D=true&columns%5B8%5D%5Borderable%5D=true&columns%5B8%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B8%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B9%5D%5Bdata%5D=id&columns%5B9%5D%5Bname%5D=&columns%5B9%5D%5Bsearchable%5D=true&columns%5B9%5D%5Borderable%5D=false&columns%5B9%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B9%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1724050584463 </code></pre> <p><strong>在蔚蓝中</strong></p> <pre><code>https://webapplication220240628111356.azurewebsites.net/Vehicles/GetAllVehicles?draw=1&columns%5B0%5D%5Bdata%5D=customerName&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=year&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=make&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=model&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=trim&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=engineSize&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=transmission&columns%5B6%5D%5Bname%5D=&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=transmissionType&columns%5B7%5D%5Bname%5D=&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=true&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B8%5D%5Bdata%5D=mileage&columns%5B8%5D%5Bname%5D=&columns%5B8%5D%5Bsearchable%5D=true&columns%5B8%5D%5Borderable%5D=true&columns%5B8%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B8%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B9%5D%5Bdata%5D=id&columns%5B9%5D%5Bname%5D=&columns%5B9%5D%5Bsearchable%5D=true&columns%5B9%5D%5Borderable%5D=false&columns%5B9%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B9%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1724050584463 </code></pre> <h3>问题似乎无法解码 url。我已经使用decodeURIComponent尝试了下面的代码,效果很好。</h3> <pre><code>@{ ViewData["Title"] = "Vehicles List"; } <h2>Vehicles List</h2> <table id="vehiclesTable" class="table table-striped table-bordered"> <thead> <tr> <th>Customer Name</th> <th>Year</th> <th>Make</th> <th>Model</th> <th>Trim</th> <th>Engine Size</th> <th>Transmission</th> <th>Transmission Type</th> <th>Mileage</th> <th>Actions</th> </tr> </thead> <tbody> </tbody> </table> @section Scripts { <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.11.3/js/dataTables.bootstrap4.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#vehiclesTable').DataTable({ "processing": true, "serverSide": true, "ajax": { "url": decodeURIComponent("@Url.Action("GetAllVehicles", "Vehicles")"), "type": "GET", "data": function (d) { var queryParams = $.param(d); return decodeURIComponent(queryParams); }, "error": function (xhr, error, thrown) { console.log("Error: ", xhr.responseText); } }, "columns": [ { "data": "customerName" }, { "data": "year" }, { "data": "make" }, { "data": "model" }, { "data": "trim" }, { "data": "engineSize" }, { "data": "transmission" }, { "data": "transmissionType" }, { "data": "mileage" }, { "data": "id", "render": function (data, type, row) { return `<a href="/Vehicles/Details/${data}" class="btn btn-info">Details</a> <a href="/Vehicles/Edit/${data}" class="btn btn-warning">Edit</a> <a href="/Vehicles/Delete/${data}" class="btn btn-danger">Delete</a>`; }, "orderable": false } ], "order": [[0, "asc"]] }); }); </script> </script> } </code></pre> <p>那么网址将是</p> <pre><code>https://webapplication220240628111356.azurewebsites.net/Vehicles/GetAllVehicles?draw=1&columns[0][data]=customerName&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=year&columns[1][name]=&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=make&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=model&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=trim&columns[4][name]=&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=engineSize&columns[5][name]=&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&columns[6][data]=transmission&columns[6][name]=&columns[6][searchable]=true&columns[6][orderable]=true&columns[6][search][value]=&columns[6][search][regex]=false&columns[7][data]=transmissionType&columns[7][name]=&columns[7][searchable]=true&columns[7][orderable]=true&columns[7][search][value]=&columns[7][search][regex]=false&columns[8][data]=mileage&columns[8][name]=&columns[8][searchable]=true&columns[8][orderable]=true&columns[8][search][value]=&columns[8][search][regex]=false&columns[9][data]=id&columns[9][name]=&columns[9][searchable]=true&columns[9][orderable]=false&columns[9][search][value]=&columns[9][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=10&search[value]=&search[regex]=false&_=1724051493112 </code></pre> <p>并且效果很好。这是测试结果。</p> <p><a href="https://i.sstatic.net/JpIMkaS2.png" rel="nofollow noreferrer"><img src="https://cdn.txt58.com/i/AWkuc3N0YXRpYy5uZXQvSnBJTWthUzIucG5n" alt="enter image description here"/></a></p> </answer> </body></html>
用于 jwt 身份验证的 Ajax 授权标头或 http cookie
将 Jwt 令牌传递给 ajax 请求调用的最佳且安全的方法是什么。 我有两个选择 选项 1. 在 ajax 标头中传递 jet 令牌,如下所示,但 Jwt 令牌在客户端响应中可见。 $.ajax({ ...
***我试图成功地将列表从控制器传递到ajax。它是来自 ajax 的 post 请求。 *** 当我尝试时,它出现为[模型模型] *这是我的控制器 公共 JsonResult CreatePackage(st...
我一直在尝试开发一个具有登录系统的网站。 作为其中的一部分,我想对服务器进行 AJAX 调用,以使用用户名和密码处理登录系统。 当我进行校准时...
AJAX asp:UpdatePanel 与 asp:Timer 从不刷新
我想我应该尝试一下计时器和更新面板。我有一个简单的页面,其中放置了 updatepanel 控件、标签和计时器。 “TICK”代码用当前更新标签...
希望你能帮助我解决这个问题。我正在尝试使用 AJAX 和 VB.NET 从服务器端获取列表到 javascript。我尝试了几件事,但它总是返回完整的文件而不是 l...
我遇到了一个问题,即我的 AJAX 调用无法到达 ASP.NET Core 应用程序中的控制器方法。尽管设置了 AJAX 调用和控制器方法,我还是收到了 404 错误。 ...
我想在用户单击该州时以模式形式显示每个州的城市列表。不幸的是,无论我做什么,我都无法解决这个问题。我将展示 ASP.NET Core 合作...
无法从 ASP.NET Core MVC 中的 Ajax 获取控制器中的数据
我正在尝试将数据从视图传递到我的控制器。我在 Ajax 中正确获取了值,但无法将它们传递给控制器。我在控制器中得到的注释始终为空。 阿贾...
我正在尝试将颜色列表(ID 号)发布到控制器中的测试功能。我知道数据正在发送并且看起来格式正确。 当我发送数据时,小提琴手显示: ...
我正在处理一个在 ASP.NET 框架上运行的非常大的项目。我正在尝试添加一些新功能以使应用程序更加用户友好,并且我需要使用ajax。我用过...