开发者

JS: Posting form directly

开发者 https://www.devze.com 2023-02-05 13:52 出处:网络
If on document.ready, I want my form to auto post itself, is this possible? So when the document has loaded, then it posts itself and takes to the action=\"\" (in this case is ?upload=true).

If on document.ready, I want my form to auto post itself, is this possible?

So when the document has loaded, then it posts itself and takes to the action="" (in this case is ?upload=true).

I heard about $.post() jquery, but this is just for posting in the b开发者_JAVA技巧ackground?


$.post() is an AJAX call and will not force the entire page to postback.

you may want to try

$(document).ready(function(){
     var form = $("#yourformid");
     form.submit();
});


Yes, $.post() in jQuery is for POST requests with AJAX.

If you want a form to submit on the document ready event, just invoke the submit itself!

$(document).ready( function()
{
  $('form').submit()
});


You want something like this:

$(function() {
  $('#myformid').submit();
});

See the documentation for jQuery's submit().

And see this working demo: http://jsfiddle.net/8hg8s/

0

精彩评论

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

关注公众号