[英]Pass Value of Text Area Ajax PHP
我敢肯定這很簡單,但是對於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變量很好地傳遞,但是Text Area只是帶有:
[object HTMLTextAreaElement]
您可以使用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() {
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.