如何在ajax mvc中显示限制结果

编程入门 行业动态 更新时间:2024-10-19 22:28:59
本文介绍了如何在ajax mvc中显示限制结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

$(document).ready(function () { //debugger; $("#txtValue").autocomplete({ source: '@Url.Action("Getbusiness")', minLength: 2, maxResults: 5 });

我从数据库表中获取所有数据..我只需要显示自动完成列表中的5个项目..怎么做?请帮我解决这个问题

Am getting all data from database table.. i need to display only 5 items in auto-complete list.. how to do that ?? kindly help me to solve this

推荐答案

(document).ready(function(){ // 调试器; (document).ready(function () { //debugger;

( #txtValue)。autocomplete({ so urce:' @ Url.Action(Getbusiness)', minLength: 2 , maxResults: 5 }); ("#txtValue").autocomplete({ source: '@Url.Action("Getbusiness")', minLength: 2, maxResults: 5 });

b $ b 我从数据库表中获取所有数据..我只需要在auto中显示5项完整清单..怎么做?请帮助我解决这个问题

Am getting all data from database table.. i need to display only 5 items in auto-complete list.. how to do that ?? kindly help me to solve this

这在jQuery中不起作用,因为实际中的jQuery不是从数据库服务器中提取数据而是它是你的服务器端语言记录,然后传递给自动完成。而不是寻找jQuery解决方案,在服务器端进行更改,更改您的SQL查询 That won't work in jQuery because jQuery in real isn't pulling the data from your database server instead it is your server-side language which is pulling the records and then passing to that autocomplete as a result. Rather than looking for jQuery solution, make changes on your server side, change your SQL query from SELECT * FROM...

to

to

SELECT TOP 5 * FROM...

这样可以确定从您的数据库中只选择了前5条记录。 jQuery与这个逻辑无关。 jQuery只会发送异步请求并提取响应。而已。实际的逻辑将在那里实现。 个人提示是将变量发送到服务器以提取数据。例如,尝试将查询字符串附加为 getbusiness?records = 5 。使用记录值并获取记录数。 永远不要对源代码进行硬编码,以后很难对其进行升级,而是根据您最近和将来的需要制作一些可以轻松编辑的案例。

This would make sure that only top 5 records are selected from your database. jQuery has nothing to do with this logic. jQuery would just send an asynchronous request and pull the response. That's it. The actual logic would be implemented there. A personal tip would be to send a variable to server to pull data. For example, try appending a query string as, getbusiness?records=5. Use the value for records and get the number of records. Never hard-code your source code, it would make it hard to upgrade it later instead make a few cases which can be easily edited as per your recent and future needs.

更多推荐

如何在ajax mvc中显示限制结果

本文发布于:2023-11-24 21:04:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626818.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   ajax   mvc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!