提交Ajax表单后,发布的值不显示在codeigniter控制器中,它将返回空数组,而不是表单中的数组值
$("#frmDemo").submit(function (e) {
e.preventDefault();
var name = $("#name").val();
var comment = $("#comment").val();
var marital_status = $('#marital_status').val();
if (name == "" || comment == "" || marital_status == "") {
$("#error_message").show().html("All Fields are Required");
} else {
$("#error_message").html("").hide();
$.ajax({
type: "POST",
url: "<?= base_url(); ?>index.php/Ajax_Post_Controller/user_data_submit",
data: "name=" + name + "&comment=" + comment + "&marital_status=" + marital_status,
success: function (data) {
$('#success_message').fadeIn().html(data);
setTimeout(function () {
$('#success_message').fadeOut("slow");
}, 2000);
}
});
}
})
空数组输出:
Array (
[name] => admin@2016comment=somnathmarital_statusjagtap
[comment] =>
[marital_status] =>
)
serialize()
如果表单具有所需的所有参数,则可以使用该表单。
var form_data=$('#frmDemo').serialize();
然后将序列化的表单传递给数据:
data:form_data
或者
如@Juhana所述,您可以传递一个对象,该对象随后将被转换为查询字符串:
data:{ name: name, comment: comment, marital_status: marital_status }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句