开发者

How to HTTP POST from a link without JS

开发者 https://www.devze.com 2022-12-11 10:21 出处:网络
Any methods to submit a POST request from a link if JS is disabled? Ideeas so far (none of them perfect)

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开发者_如何学C='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


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号