【问题标题】:How to send HTML data with inline CSS and jQuery in a PHP request?如何在 PHP 请求中使用内联 CSS 和 jQuery 发送 HTML 数据?
【发布时间】:2015-10-09 03:21:24
【问题描述】:

我正在做一个项目,我正在服务器上创建一个新的 HTML 页面,方法是发送带有内联 CSS 的 HTML 作为带有请求变量的参数。

问题在于,如果遇到# 之类的符号、&&& 之类的运算符或  < > 之类的HTML 符号代码,它就不会写入内容。


代码如下:

page.htm:

    <!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script>
            function creathtmldoc()
            {
                var data = document.getElementsByTagName('html')[0].innerHTML;
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        alert("copy created");
                        alret(xmlhttp.responseText);
                        document.getElementById("display").innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("POST", "./creatpage.php?data="+data, true);
                xmlhttp.send();


            }
        </script>
    </head>
    <body>
        <div id="display">
            <div id="mydiv" style="border:2px solid #dddddd;margin: 0 auto;padding:70px;width:660px;height:900px;">
                <div style="clear:both;">
                    <div style="float:left;">Hello <strong>Gaurav</strong></div>
                    <div style="float:right;"><strong>&lt;@Your name&gt;</strong></div>
                </div>
                <div style="clear:both;">
                    <div style="float:left;">We are : <span style="font-family:courier new,courier,monospace"><em><strong>&lt;@Company name&gt;</strong></em></span></div>
                    <div style="float:right;"><em><strong><span style="font-family:courier new,courier,monospace">&lt;@Your designation&gt;</span></strong></em></div>
                </div>
                <div style="clear:both;">
                    <div style="float:left;"><span style="font-family:courier new,courier,monospace"><em><strong>&lt;@Company name with full address of company&gt;</strong></em></span></div>
                    <div style="float:right;"><span style="font-family:courier new,courier,monospace"><em><strong>&lt;@Your contact&gt;</strong></em></span></div>
                </div>
                <div style="clear:both;">&nbsp;</div>
                <div style="clear:both;">
                    <hr />
                    <div>We call you to inform about : <span style="font-family:courier new,courier,monospace"><em><strong>&lt;@Subject&gt;</strong></em></span></div>
                    <hr /></div>
                <br />
                Dear:<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We call you to inform about :<span style="font-family:courier new,courier,monospace"><em><strong>&lt;@Your message should be here !&gt;</strong></em></span><br />
                &nbsp;
                <hr />
                <div style="float:right;">Your sincerely<br />
                    <span style="font-family:courier new,courier,monospace"><em><strong>&lt;@Your name&gt;</strong></em></span></div>
            </div>
            <input type="button" onclick="creathtmldoc()" value="creat a copy of this html page >>"/>
        </div>
    </body>
</html>

createpage.php

    <?php
$myfile = fopen("newpage.html", "w") or die("Unable to open file!");
fwrite($myfile, $_REQUEST["data"]) or die("Unable write!");
fclose($myfile);
echo $_REQUEST["data"];
 ?>

通过这个演示,我想展示这个问题:这段代码没有做我想做的事情;它不是创建页面的副本。如何解决?

如何在 PHP 请求中使用内联 CSS 和 jQuery 发送 HTML 数据?

【问题讨论】:

    标签: php ajax xmlhttprequest httprequest


    【解决方案1】:

    你试过encodeURIComponent() javascript函数吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-22
      • 2020-05-03
      • 2021-11-23
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      相关资源
      最近更新 更多