开发者

jquery selection to post value

开发者 https://www.devze.com 2023-01-21 05:41 出处:网络
I am trying to use jquery to grab the contents of a div and pass it to a php script that emails it. So I need to use a $(\'#div\').html() and send that 开发者_如何转开发to a $_POST[\'\'] value. Any id

I am trying to use jquery to grab the contents of a div and pass it to a php script that emails it. So I need to use a $('#div').html() and send that 开发者_如何转开发to a $_POST[''] value. Any ideas?


(From jQuery's 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 );
   }
 });


Or you may also want to try this:

$.post('ajax/sendEmail.php',
    { body : $('#div').html() }, 
    function(msg) { 
        alert("Email was sent: " + msg);
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号