使用 jquery 和 asp.net 进行渐进式增强

发布于 2025-01-04 09:19:33 字数 210 浏览 2 评论 0原文

我已经建立了一个无需任何 JavaScript 即可正常工作的网站(我什至避免使用链接按钮)。现在我想使用 javascript 使用 jquery 和 json 来实现更丰富的交互式网站。有人可以向我展示一个提交按钮的示例,该按钮在启用 JavaScript 时与 jquery 和 json(用于将数据提交到服务器的部分回发)一起使用。当 javascript 被禁用时,它应该执行正常的服务器端发布。

I have built a website which working fine without any javascript (I have even avoided using link button). Now i want to use javascript using jquery and json for richer interactive website. Can somebody show me with example of a submit button which work with jquery and json (partial postback for submitting data to server) when javascript is enabled. when javascript is disabled it should do normal server side posting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2025-01-11 09:19:33

有很多方法可以实现这种“双重动作”,我可以给你一个想法。首先,您创建一个处理程序来完成您的工作并执行您的命令。然后,您可以简单地认为通过链接和 url 参数调用此命令。

例如:

<a class="AjaxCallsClass" href="dothiswork.ashx?WorkID=23">Show This</a>

现在,您同时使用 jQuery 在链接上放置 javascript 来捕获 onclick 因此,如果用户启用了 javascript,您可以添加额外的代码,使用 ajax 来调用相同的命令,获取结果并将其打印在页面上。

因此,无论有没有 javascript,命令都是相同的,您只需要对输出的方式进行一些操作即可。

我希望这会有所帮助。

There many way to do this "double action", I can give you one idea. First you make a handler that make your work and execute your commands. Then you make the simple easy think to call this command via link and url parameters.

eg:

<a class="AjaxCallsClass" href="dothiswork.ashx?WorkID=23">Show This</a>

Now at the same time you use jQuery to place on your links javascript to capture the onclick So if the user have enable the javascript, you add extra code that use ajax to call the same command, get the results and print it on page.

So with or with out javascript the command is the same, and you only need to manipulate a little the way the output will be.

I hope that this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文