我正在尝试使用jquery来获取div的内容并将其传递给通过电子邮件发送的php脚本。所以我需要使用$('#div')。html()并将其发送到$ _POST ['']值。有什么想法吗?
答案 0 :(得分:3)
(来自jQuery的docs):
$.ajax({
type: "POST",
//your PHP file
url: "some.php",
//passing contents $_POST['body'] will be your body.
data: "body=" + $('#div').html(),
//msg is your PHP scripts' response
success: function(msg){
alert( "Data Saved: " + msg );
}
});
答案 1 :(得分:0)
或者您可能也想尝试一下:
$.post('ajax/sendEmail.php', { body : $('#div').html() }, function(msg) { alert("Email was sent: " + msg); });