简体   繁体   English

HTML 上 POST/DELETE 链接的最佳实践

[英]Best practices for POST/DELETE links on HTML

I don't want to use GET method for some destructive links (like deleting an item, remove something…) so I use POST or DELETE actions on my links, with a Javascript AJAX request like this:我不想对某些破坏性链接使用 GET 方法(例如删除项目、删除某些内容……),因此我对链接使用 POST 或 DELETE 操作,并使用 Javascript AJAX 请求,如下所示:

<a class="js-link" data-method="DELETE" data-confirmation="Are you sure?" data-href="xxx">

I don't use href because the URL is not available with a GET method (error 405).我不使用href因为 URL 不适用于 GET 方法(错误 405)。

My questions are:我的问题是:

  • What are the best-practices for these kind of links?此类链接的最佳实践是什么?
  • Is this valid HTML?这是有效的 HTML 吗?
  • What about users without JS, old browsers?没有 JS 的用户,老浏览器怎么办?

Thanks:)谢谢:)

As mentioned in the comments, the appropriate solution here is to use a <button> or similar.正如评论中提到的,这里的适当解决方案是使用<button>或类似的。 Since these are not hypertext links that you can follow , which can be followed by eg search engine crawlers, they should not be represented using the <a> hypertext anchor element.由于这些不是您可以跟踪的超文本链接,例如搜索引擎爬虫可以跟踪这些链接,因此不应使用<a>超文本锚元素来表示它们。

Note that according to the standard :请注意,根据标准

If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.如果 a 元素没有 href 属性,则该元素代表一个占位符,用于放置链接,如果它是相关的,则仅包含元素的内容。

so your usage of href -less <a> does not match the standard's definition.因此您对href -less <a>的使用与标准的定义不符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM