php+ajax批量生成html页面

<!--生成静态-->

<?php
require_once("../config.php");
ob_start();

$abc='haha';
$smarty->assign("showtitle",$abc);
$smarty->display("jth.html");
$this_my_f= ob_get_contents();
ob_end_clean();
$filename = "jth.html";
$toto=tohtmlfile_cjjer($filename,$this_my_f);

// 文件生成函数
function tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content){
if (is_file ($file_cjjer_name)){
@unlink ($file_cjjer_name); //存在,就删除
}
$cjjer_handle = fopen ($file_cjjer_name,"w"); //创建文件
if (!is_writable ($file_cjjer_name)){ //判断写权限
return false;
}
if (!fwrite ($cjjer_handle,$file_cjjer_content)){
return false;
}
fclose ($cjjer_handle); //关闭指针
return $file_cjjer_name; //返回文件名
}
header("location:$filename"); //测试使用。。。
?>

<!--批量-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>XMLHttpRequest</title>
<script language="javascript" type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject)
   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
   xmlHttp = new XMLHttpRequest();
}
function startRequest(url){
createXMLHttpRequest();
//var page=document.getElementById("page");
//var url=page.value.replace(/(^\s*|(\s*$))/g,"");
var sUrl = url+".php?" + new Date().getTime();
xmlHttp.open("GET",sUrl,true);
var showR=document.getElementById("showR");
xmlHttp.onreadystatechange = function(){
   showR.innerHTML='正在更新'+url+'.html数据。。';
   if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
    //alert("suf");
    showR.innerHTML='选中页面数据更新成功';
}
xmlHttp.send(null);
}

function SelectAll() {
var checkboxs=document.getElementsByName("ch");
for (var i=0;i<checkboxs.length;i++) {
var e=checkboxs[i];
e.checked=!e.checked;
}
}

function update(){
var a=document.getElementsByName("ch");
var b=new Array();
for(var i=0; i<a.length; i++) {
if(a[i].checked) {
b.push(a[i].value);
   }
}
//return b;
for(var i=0;i<b.length;i++){
//alert(b[i]);
startRequest(b[i]);
}
}
</script>
</head>
<body>
<div id="showR"></div>
<form name="form1">
<input id="ch" name="ch" type="checkbox" value='jth'>jth
<input id="ch" name="ch" type="checkbox" value='jth2'>jth2
<input id="ch" name="ch" type="checkbox" value='jth3'>jth3
<input id="ch" name="ch" type="checkbox" value='jth4'>jth4
<input id="ch" name="ch" type="checkbox" value='jth5'>jth5
<input type="button" onClick="SelectAll()" value="全选/反选">
<input type="button" onClick="update()" value="提交">
</form>
</body>
</html>

posted @ 2012-07-24 15:04  暮色灯塔  阅读(492)  评论(0编辑  收藏  举报