Javascript 如何在下面的代码中传递textarea数据?
我正在提交我的表单,在表单中我发送文本区域和文本框数据,但我没有得到文本区域的详细信息 那么我如何在下面的代码中传递文本区域的详细信息呢Javascript 如何在下面的代码中传递textarea数据?,javascript,php,jquery,json,laravel,Javascript,Php,Jquery,Json,Laravel,我正在提交我的表单,在表单中我发送文本区域和文本框数据,但我没有得到文本区域的详细信息 那么我如何在下面的代码中传递文本区域的详细信息呢 $(document).on('click','#contactsave',function(e){ e.preventDefault(); //keeps the form from behaving like a normal (non-ajax) html form var $form = $("#contactForm
$(document).on('click','#contactsave',function(e){
e.preventDefault(); //keeps the form from behaving like a normal (non-ajax) html form
var $form = $("#contactForm");
var url = $form.attr('action');
var formData = {};
//submit a POST request with the form data
$form.find('input').each(function(){
formData[ $(this).attr('name') ] = $(this).val();
});
$('.blockui').show();
$('.overlayblock').show();
$.post(url, formData, function(response)
{
var obj = $.parseJSON(response);
if(obj.status == 1){
$(".succmsg").html(obj.message);
}else{
$(".succmsg").html(obj.message);
}
$("#description").val(''); $("#emails").val(''); $("#mobile").val(''); $("#name").val('');
setTimeout( function(){$('.succmsg').html('');} , 4000);
$('.blockui').hide();
$('.overlayblock').hide();
}).fail(function(response)
{
$.each(response['responseJSON'],function(value, index){
$("#"+value).parent(".form-group").addClass("has-error");
$("#"+value).siblings(".error").html(index);
});
$('.blockui').hide();
$('.overlayblock').hide();
});
});
或
试试这个,因为您只得到
输入
键入每个语句
$form.find('input').each(function(){
formData[ $(this).attr('name') ] = $(this).val();
});
使用jquery的serialize()
函数,那么所有元素的值都将被发送
var formData = $("#contactForm").serialize();
$.post({
data: formData ,
dataType: "json",
success: function(data) {
},
error: function() {
}
});
您可以尝试以下方法:
$('form').serialize()
在这个例子中:
<form>
<input type="radio" name="foo" value="1" checked="checked" />
<input type="radio" name="foo" value="0" />
<input name="bar" value="xxx" />
<select name="this">
<option value="hi" selected="selected">Hi</option>
<option value="ho">Ho</option>
</form>
您好!
霍
这将产生:“foo=1&bar=xxx&this=hi”
$('form').serialize()
<form>
<input type="radio" name="foo" value="1" checked="checked" />
<input type="radio" name="foo" value="0" />
<input name="bar" value="xxx" />
<select name="this">
<option value="hi" selected="selected">Hi</option>
<option value="ho">Ho</option>
</form>