2014-01-14 89 views
0

我通過Ajax發送一個聯繫表單,所有值都發送並處理正常,但由於某種原因郵件內容沒有從textarea字段傳遞,我試過var note = $("textarea#note").text();var note = $("textarea#note").val();我我也嘗試過與$("$note"),但仍無濟於事。我相信文本區域的價值正在被拾起,但它不會傳入字符串。通過Ajax傳遞Textarea字段到php

這裏是我的代碼:

$('#formsend').click(function(){ 

var detail = $("input#subject").val(); 
var note = $("textarea#note").text(); 

var dataString = $('form').serialize(); 

$.ajax({ 
    type: "POST", 
    url: "processmail.php", 
    data: dataString, 
    success: function() { 
    $('#form').html("<div id='message'></div>"); 
    $('#message').html("<h2>Message Submitted.</h2>") 
    .append("<p>Thank you for contacting me, I will be in touch soon.</p>") 
    .hide() 
    .fadeIn(1500); 
    } 
}); 
return false; 

}); //end form ajax 

,但我試圖傳遞的數據爲:

data:{ 
     'detail': detail 
     'note': note 
     } 

兩種方法似乎與各個領域的合作,除了他們沒有通過文本區域的價值通過我的PHP文件。

任何想法?

+1

簡單地使用'$( 「#筆記」)VAL()' - 這應該工作如果y。你有textarea像'' – Philipp

回答

0

試試這個,你可以通過這個$("$note")獲取內容,你應該使用$("#note")

$('#formsend').click(function(){ 

var detail = $("input#subject").val(); 
var note = $("#note").text(); 

var dataString = $('form').serialize(); 

$.ajax({ 
    type: "POST", 
    url: "processmail.php", 
    data: dataString, 
    success: function() { 
    $('#form').html("<div id='message'></div>"); 
    $('#message').html("<h2>Message Submitted.</h2>") 
    .append("<p>Thank you for contacting me, I will be in touch soon.</p>") 
    .hide() 
    .fadeIn(1500); 
    } 
}); 
return false; 

}); 
0

只需使用$( 「#筆記」)VAL() - 這應該工作,如果你有textarea的id爲note

<textarea id="note">..</textarea> 

JS:

$('#formsend').click(function(){ 


var detail = $("input#subject").val(); 
var note = $("#note").val(); 

$.ajax({ 
    type: "POST", 
    url: "processmail.php", 
    data: {detail: detail, note: note}, 
    success: function() { 
    $('#form').html("<div id='message'></div>"); 
    $('#message').html("<h2>Message Submitted.</h2>") 
    .append("<p>Thank you for contacting me, I will be in touch soon.</p>") 
    .hide() 
    .fadeIn(1500); 
    } 
}); 
return false; 

});