I want to achieve the same as...
window.open('lalala.php', 'lalala', '...');
But I want to send a HTTP POST request instead of a HTTP GET request. Thus, I'm using the following:
$('<form/>').attr('action', 'lalala.php')
.attr('target', 'lalala') // w3schools.org says this is deprecated
.attr('method', 'post')
.append(hiddenParam('param1', param1))
.append(hiddenParam('param2', param2))
.submit().remove();
// hiddenParam is a function I created that returns an input tag
// the type attribute set to hidden,
// the id attribute set to the first parameter,
// and the value attribute set to the second parameter
However, the target
attribute is deprecated. Is there any way to achieve what I'm trying to do by non-deprecated means?
Use target
— it isn't deprecated.
target
is only missing in strict doctypes. It is not deprecated. The simplest solution is to use a transitional doctype.Just be aware of this 'bug' in just about every browser. The solution is to serve your XHTML as application/xhtml+xml
, but this will cause IE to blow up, so you need to sniff for that browser before determining the content type. It's essentially one giant hack for a tiny check box on a validation form. It's usually a lot simpler to just use a transitional doctype.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [ <!ATTLIST form target CDATA #IMPLIED> ]>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With