<!-- xxx.php -->
<?php
if(isset($_GET['save'])){
    file_put_contents($_GET['save']);
}
?>
<script language="javascript">
var xmlHttp;
    function createXMLHttpRequest() {
        if(window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }    
    }
function saveDiv(){
        createXMLHttpRequest();
                var info=document.getElemntById("info").innerHTML;
        url = "xxx.php?save="+info+"&ran="+Math.random();
        method = "GET";
        xmlHttp.open(method,url,true);
        xmlHttp.onreadystatechange = function(){alert("已保存");};
        xmlHttp.send(null);
    }
</script>
<form id="sendlist" name="sendlist" action="xxx.php" method="post">
    <input type="button" name="save" value="保存" onclick="saveDiv()" />
        <div id="info">
            标题一
             标题二
        </div>
</form>
想要做成保存到txt里面,还是一样一个标题,每50个保存到一个txt里,然后按1.txt/2.txt这样的顺序保存下来

解决方案 »

  1.   

    ajax推荐使用已经封装的代码,比如jquery
      

  2.   

    document.getElementById("info").innerHTML;
    另外xmlHttp.onreadystatechange = function(){alert("已保存");};逻辑上有问题,出错没出错都一样了。
    至于你说的PHP保存,本身没有什么难度,只是代码量的问题。我想没人愿意大晚上的还写那么多的代码,至少我有那工夫宁愿看一部电影去。还得你自己琢磨。参考资料:http://www.php.net/manual/zh/ref.filesystem.php