How to HTTP POST from a link without JS

2019-02-16 10:49发布

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

3条回答
三岁会撩人
2楼-- · 2019-02-16 11:02

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.

查看更多
干净又极端
3楼-- · 2019-02-16 11:12

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.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-02-16 11:20

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.

查看更多
登录 后发表回答