简体   繁体   中英

Create new page dynamically on onclick

Very new to this, but through the help of posts on here i have gotten quite far, i think i am at the last step but i have gotten stuck.

I am trying to dynamically create a new products page in the admin panel , so every time a administrator clicks the onclick button a new webpage is created, with the content from the new products page, which i have already created and append a link so the administrator and continuously gain access to each product.

I have been able to get a pop up to appear saying the Page has been created. But wasn't able to gain access to the page that was created. So i changed the code to attempt to show the links to the created code and append the links.

Now that i have changed it nothing happens on onclick,I have been looking at the code for hours on end and cannot find the solution. Probably obvious to pros like yourselves but as a newbie my brain is now fried.

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;
?>

Any suggestions? related pages i can read up on. Anything will be extremely appreciated.

I think you should change var xmlhttp = document.createElement('a'); into that: var createA = document.createElement('a');

Because the xmlhttp is already created and used for the ajax request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM