[英]Sending a lot of fields through a post AJAX request
I have like 143 form fields (text, textarea and select) that I would like to send through an AJAX post request.我有 143 个表单字段(文本、文本区域和选择),我想通过 AJAX 发布请求发送它们。 Is there a way I can do this quick without manually add every field to the query?
有没有一种方法可以在不手动将每个字段添加到查询的情况下快速完成此操作?
Alright so I've set up thing like this:好的,所以我已经设置了这样的东西:
jquery查询
$("#submitbtn").click(function(){
$.ajax({url: "check_data.php", data: $("#form").serialize(), success: function(result){
alert(result);
}});
}); });
The form is declared like this:表格声明如下:
<form class="pure-form" onsubmit="return false;" method="POST" id="form">
I tried also without the "return: false"我也试过没有“返回:假”
And the button as follow:按钮如下:
<button id="submitbtn" class="pure-button pure-button-primary">INSERT</button>
But it does not work, when I press the button I get no js or network activity whatsoever on the console, and nothing happens.但它不起作用,当我按下按钮时,控制台上没有任何 js 或网络活动,也没有任何反应。
I solved it by using this:我用这个解决了它:
$(function() { $("#form").on("submit", function(event) { event.preventDefault(); $.ajax({ url: "check_data.php", type: "POST", data: $(this).serialize(), success: function(d) { alert(d); } }); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.