这是一个全新的概念,但通过这里的帖子,我已经走了很长的路,我想我已经走到了最后一步,但我已经陷入了困境。
我正试图在管理面板中动态创建一个新产品页面,因此每次管理员单击onclick按钮时,都会创建一个带有新产品页面内容的新网页,我已经创建了新产品页面并添加了一个链接,以便管理员能够持续访问每个产品。
我已经能够得到一个弹出窗口显示页面已经创建。但无法访问创建的页面。因此,我更改了代码,试图显示创建代码的链接,并附加链接。
既然我已经更改了它,onclick上什么都没发生,我已经连续看了几个小时的代码,却找不到解决方案。对于像你们这样的职业选手来说,这可能是显而易见的,但作为一个新手,我的大脑现在被炸了。
HTML
<html>
<body>
<button onclick="makePage()">click</button>
<script src="makePage.js">
</script>
</body>
</html>
JS-
function makePage(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var xmlhttp = document.createElement('a');
var createAText = document.createTextNode(xmlhttp.responseText);
createA.setAttribute('href', xmlhttp.responseText);
createA.appendChild(createAText);
document.body.appendChild(createA);
}
}
}
PHP
<?php
$content = $_GET["content"];
//$file = uniqid() . ".html";
//file_put_contents($file, $content);
$current=file_get_contents($file);
file_put_contents($file, $current, FILE_APPEND | LOCK_EX);
echo $file;
?>
有什么建议吗?我可以在相关页面上阅读。任何内容都将不胜感激。
我认为您应该更改var xmlhttp = document.createElement('a');
转换为:var createA = document.createElement('a');
因为xmlhttp已经创建并用于ajax请求。