dtbhp60824
2015-03-03 15:44 阅读 41

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 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.

    点赞 评论 复制链接分享
  • dousenjue3214 dousenjue3214 2015-03-03 16:10

    the file that has the script has to be a php file or it won't work, because it will not be parsed by php.

    Let me know if that's the case...

    点赞 评论 复制链接分享

相关推荐