将HTML页面的内容发送到PHP文件

时间:2014-04-25 09:13:29

标签: php jquery

如何将HTML文件的内容发送到php文件。实际上我使用下面的代码

在jquery变量中获得了总HTML内容
$(document).ready(function(){
  $("#btnExportpdf").click(function(){
var html= $("#tblExport").html();
});
});

我被困在这里,如何将这么大的字符串发送到新的PHP页面? 请提供一个示例或链接

2 个答案:

答案 0 :(得分:0)

你必须对.php文件进行POST。 使用jQuery POST函数。

var html = 'Here <b>some</b> text!';

$.post( "example.php", html, function() {
  alert( "success" );
})
  .done(function() {
    alert( "second success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "finished" );
});

jQuery文档中的更多信息:
https://api.jquery.com/jQuery.post/&amp;&amp; https://api.jquery.com/jQuery.ajax/

答案 1 :(得分:-1)

您可以通过ajax将数据从Javascript发送到php

    $(document).ready(function(){
      $("#btnExportpdf").click(function(){
       var html= $("#tblExport").html();
       $.ajax({ 
          type: "POST",            // Methode POST or GET
           url: "some.php",        // PHP file to processing the data
           data: { "html": html }  // post variables that will handetover to php
       })
       .done(function( msg ) {     // response
          console.log(msg)         // data retuned from php
        });
    });
    });

JQuery AJAX