dtbhp60824 2015-03-03 15:44
浏览 44
已采纳

jquery:将php include文件添加到jquery内容?

I am using the following jquery:

<script>
setTimeout(function() {
$(".home_column").flip({
    direction:'rl',
        color: 'rgba(138, 138, 138, 0.2)',
    content:'this is my new content'
});
}, 2500);
</script>

what I am trying to do is replace the content of the jquery where it says 'this is my new content' with a php file called login_form.php.

I have tried the following:

content:'<?php include 'login_form.php'; ?>'

however this does not work. if I use php within the content my jquery just stops working all together. my login_form.php file includes a form with 2 input boxes. can someone please show me how this can be done, thanks in advance

  • 写回答

2条回答 默认 最新

  • duanbiao4035 2015-03-03 16:21
    关注

    I would guess that you are running into problems because the rendered PHP page will contain unescaped single quotes, which will clash with the single quotes you are using to define the string (below) from your example:

    content:'<?php include 'login_form.php'; ?>'
    

    Answer: If, instead, you were to actually include the rendered content into a hidden element of the page/DOM, then you could access it that way and assign it.

    <div id="loginSource" style="visibility: hidden;"><?php include 'login_form.php'; ?></div>
    

    Then you could do something like this for the assignment:

    <script>
    var loginSource = $("#loginSource").html();
    setTimeout(function() {
    $(".home_column").flip({
        direction:'rl',
            color: 'rgba(138, 138, 138, 0.2)',
        content: loginSource
    });
    }, 2500);
    </script>
    

    This is just a guess. I've not tested it. I don't actually ever work in PHP.

    Hope it helps.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度