我确信这很简单,但对AJAX来说是新手,所以可以使用指针。我看到其他人有这个问题,但找不到明确的答案。
我有一个带有文字区域的表格
<form name='comment_form' method="post">
<textarea name='comment' id="comment" value="" cols="100" rows="3"/></textarea>
<input type="button" value="Send" onClick="process_comment();">
</form>
我已经删除了很多,因为表格中有很多。
所以在函数中我设置了变量:
var comment=document.getElementById("comment").value
然后用ajaxrequest.send传递它,如:
comment="+encodeURIComponent(comment)
作为字符串的一部分,这适用于表单上的文本框,但文本区域的值为:
[object HTMLTextAreaElement]
我确定它包含文本区域的值,但我无法找到如何显示它。我正在使用PHP:
$comment = $_POST['comment'];
任何指针都会很棒。
确定这一切都适用于文本框,我使用相同的方法来设置值,例如:
var comment=document.getElementById("comment").value
ajax发送是:
ajaxRequest.send("first_name="+encodeURIComponent(first_name)+"&last_name="+encodeURIComponent(last_name)+"&shipping_company="+encodeURIComponent(shipping_company)+"&shipping_address_1="+encodeURIComponent(shipping_address_1)+"&shipping_address_2="+encodeURIComponent(shipping_address_2)+"&shipping_city="+encodeURIComponent(shipping_city)+"&shipping_postcode="+encodeURIComponent(shipping_postcode)+"&shipping_zone="+encodeURIComponent(shipping_zone)+"&shipping_country="+encodeURIComponent(shipping_country)+"&email="+encodeURIComponent(email)+"&order_id="+encodeURIComponent(order_id)+"&order_status_id="+encodeURIComponent(order_status_id)+"¬ify="+encodeURIComponent(notify)+"&comment="+encodeURIComponent(comment)+"&date_added="+encodeURIComponent(date_added));
所有其他值都很好地传递了post变量,但是文本区域只是出现了:
[object HTMLTextAreaElement]
答案 0 :(得分:-2)
您可以使用jQuery的ajax方法。
$.ajax({
type: 'POST',//GET
url: "abc.do",
data : {"comments":$("#comments").val(),
dataType: 'json',
cache: true,
context:this.id,
success: function(data){},
error: function() {},
beforeSend: function() {},
complete: function() {
}
});