开发者

Injecting the result of PHP code into a Javascript alert box

开发者 https://www.devze.com 2023-03-05 11:09 出处:网络
开发者_运维百科I\'ve recently been designing a website for a client, and have run into a slight difficulty in Javascript - I need to have either a <?php include()?>, or a form (the former being

开发者_运维百科I've recently been designing a website for a client, and have run into a slight difficulty in Javascript - I need to have either a <?php include()?>, or a form (the former being of more use) within a Javascript alert box.

Is there any way to do this? Thanks. :)


The alert function can only show plain text.

You need to use a fake modal dialog, such as jQuery UI Dialog.


One PHP page:

<script type="text/javascript">
alert("<?php include("otherpage.php"); ?>");
</script>

otherpage.php:

echo "Hello, world";

Of course, the output of otherpage.php can only be plain text, and must have properly escaped quotes. If you need to do anything else, you will need a different solution than JavaScript's alert.


Does it have to be an alert box? Can it not be a lightbox?

The jquery UI dialog box may be of some help. it hasa dialog box with a form

jQuery UI Dialog Box

Personally if you want a form in a box to pop up on click or something I would use a lightbox.

Hope this helps,

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号