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

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

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.

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