douhuang9886 2011-04-26 10:55
浏览 29
已采纳

将Javascript字符串传递给PHP输出

I'm using this web service that prints out table using Javascript functions. I need the table to print out in plain html. This could be done if the Javascript string was transferred to a PHP file. So basically, this is similar to AJAX, but it is in reverse.

  • 写回答

4条回答 默认 最新

  • duanmeng3573 2011-04-26 11:12
    关注

    You could do that with ajax also

    var value = 'This is a test';
    if ($(value).val() != 0) {
    $.post("jquery2php.php", {
        variable:value
    }, function(data) {
        if (data != "") {
            alert('We sent Jquery string to PHP : ' + data);
        }
    });
    }
    

    Important thing here is we are using $.post, so we are can gather the information with $_POST

    We are sending only 1 value, named variable.

    PHP part;

    <?php 
    $jqueryVariable = $_POST['variable'];
    echo $jqueryVariable;
    ?>
    

    I believe, this is the most elegant way to achieve what you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探