This is my first time using AJAX i have been reading up on it, and it is also my first time doing this with js. I think i have confused myself along the way.
I am trying to dynamically create a new restaurant page, so every time a administrator clicks the onclick button a new webpage is created, with the content from the new restaurant page, which i have already created.
At the moment i have gotten as far as on pressing a button, a new webpage is created succesfully, however, i have no idea how to access the new webpage i also wanted to display a link to the newly created webpage as it is created, like for example using before. in js to show the dynamic feature before my o'clock button for example.
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)
alert("webpage " + xmlhttp.responseText + " was successfully created!");
}
var content = "<html><head><meta charset=\"utf-8\" /> </head><body>new website<script>alert(\"test\")</script></body></html>";
xmlhttp.open("GET","makePage.php?content=" + content,true);
xmlhttp.send();
}
PHP
<?php
$content = $_GET["content"];
$file = uniqid() . ".html";
file_put_contents($file, $content);
echo $file;
?>
Any suggestions? guidance or related pages i can read up on. Anything will be extremely appreciated.