admin管理员组文章数量:1300009
I am trying to submit a form thru javascript on the fly (using jquery-form)
Is it possible to create 'FORM' update bunch of values in that 'FORM' using javascript without having HTML-form ?
I am trying to submit a form thru javascript on the fly (using jquery-form)
Is it possible to create 'FORM' update bunch of values in that 'FORM' using javascript without having HTML-form ?
Share Improve this question asked Sep 12, 2009 at 9:20 NigerNiger 4,0065 gold badges31 silver badges30 bronze badges4 Answers
Reset to default 5I'm going to guess that what you're asking is 'Can I perform an HTTP POST without using an HTML form?' The answer is yes.
Check out jquery's $.post(). It would look something like this:
$.post(url, { value1: "foo", value2: "bar" } );
Where the variable names you're passing are value1/value2 with their corresponding values.
Here's the jquery reference: $.ajax
This code will create a form on the fly, populate it with the data passed in and submit it (as a regular HTTP POST). This should be what you need.
var postRequest = function (uri, data) {
data = data || {};
var form = $('<form method="post" class="js:hidden">').attr('action', uri);
$.each(data, function(name, value) {
var input = $('<input type="hidden">')
.attr('name', name)
.attr('value', value);
form.append(input);
});
$('body').append(form);
form.submit();
};
I think you mean one of the following two things:
Can I create a
<form>
element using javascript?
A: Yes, you can.
Use jQuery DOM manipulation functions to do that.Can I submit values to a server side script like a
<form>
would?
A: Yes, you can.
Use jQuery Ajax functions to do so. More specifically, jQuery.post() is your friend.
jQuery form plugin can e in handy if you want to do something in between these two options.
Cheers!
You can post all the values in the form through
$.ajax({url: XXX, data: { formField1: "value" }})
本文标签: Creating 39form39 in javascript without html formStack Overflow
版权声明:本文标题:Creating 'form' in javascript without html form - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741656174a2390773.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论