Javascript 我的jquery构建表单正在提交,但没有发送任何值!
我正在尝试做一些类似于这里找到的插件的事情: 做我本来打算用它,但它在日期上有很多麻烦。所以我想我应该试着把它改大一点 以下是我的插件版本:Javascript 我的jquery构建表单正在提交,但没有发送任何值!,javascript,jquery,forms,post,Javascript,Jquery,Forms,Post,我正在尝试做一些类似于这里找到的插件的事情: 做我本来打算用它,但它在日期上有很多麻烦。所以我想我应该试着把它改大一点 以下是我的插件版本: jQuery.download = function (url, data, method) { if (url && typeof data == 'object') { //for this version, data needs to be a json object. //loop through the dat
jQuery.download = function (url, data, method) {
if (url && typeof data == 'object') {
//for this version, data needs to be a json object.
//loop through the data object..
var theForm = $('<form></form>').attr('action', url).attr('method', method).attr('id', 'jqueryDownloadForm');
$.each(data, function (propertyName, propertyVal) {
theForm.append($("<input />").attr('type', 'hidden').attr('id', propertyName).val(propertyVal));
});
theForm.appendTo('body').trigger('submit').remove();
}
else {
//they didn't fill in the params. do nothing
}
它构建表单并提交。但它不发送任何输入
如果我遍历form.find('input'),它们都有值。但是,用菲德勒的眼光看这篇文章,却什么也没有发表。我的mvc控制器给了我空参数错误
提前感谢您的帮助
编辑:
我尝试在表单中添加一个按钮。像这样:
theForm.append($("<input />").attr('type', 'submit').attr('id', "ExportForm").val("Export"));
form.append($(“”).attr('type','submit').attr('id','ExportForm').val(“Export”);
而不是从JavaScript提交。如果我单击该按钮,它也不会发送任何数据。您正在生成的
元素没有名称
属性。由于该属性(不是id
)用于在发布表单时标识控件,因此实际上不会向服务器提交任何内容
尝试以下方法:
theForm.append($("<input />").attr("type", "hidden")
.attr("name", propertyName).val(propertyVal));
form.append($(“”).attr(“type”,“hidden”)
.attr(“name”,propertyName).val(propertyVal));
提交后,您是否尝试在函数末尾添加返回false?没用。
theForm.append($("<input />").attr("type", "hidden")
.attr("name", propertyName).val(propertyVal));