How to HTTP POST from a link without JS

不问归期 提交于 2019-11-30 23:13:25

问题


Any methods to submit a POST request from a link if JS is disabled?

Ideeas so far (none of them perfect)

  1. Use <input type='submit>, but I need a link not a button
  2. Use <a href='' onclick='form.submit()' > but that relies on JS
  3. Use <input type='image'> ... again .. not really a link

I need a fallback method for browsers without JS, and my area for these "buttons" is too small for buttons or images


回答1:


You could make the button look like a normal link if you want using CSS?

Something like this perhaps?

<style type="text/css" media="screen">
input {
  border: none;
  background: none;
  color: #00f;
  text-decoration: underline;
  cursor: pointer;
  display: inline;
  margin: 0;
  padding: 0;
}
</style>

Click <input type="submit" value="here"/>!

Edit to add: The following CSS is just an example of how it might work, though not thorougly tested and to make it look like one of your normal links you might need to tweak it a bit.




回答2:


No, there isn't.

Links afford going somewhere. Buttons afford sending data somewhere.

If you want to use a link to make a POST request, then you are either sending confusing signals to users or you have your backend setup to use the wrong type of HTTP request for the task.




回答3:


The one solution I can think of is to have a form on the page with a button styled so that it simply looks like a text link.

When Javascript is enabled, you can gracefully hide this form and allow the normal link to take precident and if Javascript is disabled, allow the user to still use the system.



来源:https://stackoverflow.com/questions/1747869/how-to-http-post-from-a-link-without-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!