JQuery: Convert GET URL to POST
JQuery: Convert GET URL to POST
what's the easiest way to convert a GET URL string to POST in jQuery?
e.g. I want the params of a link
<a href="/somepage?x=1&y=3" id="postlink">link</a>
to be submitted as POST onclick if javascript is activated. No AJAX, just normal form submitting.
Any Ideas?
Thanks, Hannes.
I just write this code, check please, may be it helpful http://jsfiddle.net/AEwxt/
$('#postlink').click(function() {
var p = $(this).attr('href').split('?');
var action = p[0];
var params = p[1].split('&');
var form = $(document.createElement('form')).attr('action', action).attr('method','post');
$('body').append(form);
for (var i in params) {
var tmp= params[i].split('=');
var key = tmp[0], value = tmp[1];
$(document.createElement('input')).attr('type', 'hidden').attr('name', key).attr('value', value).appendTo(form);
}
$(form).submit();
return false;
});

浙公网安备 33010602011771号