html php js ajax请求,javascript – PHP / JS / AJAX / HTML:动态创建网页

这是我第一次使用AJAX,我一直在阅读它,这也是我第一次使用js.我想我一直困惑自己.

我正在尝试动态创建一个新的餐馆页面,因此每次管理员点击onclick按钮时,都会创建一个新网页,其中包含我已经创建的新餐厅页面中的内容.

目前我已经按下按钮,成功创建了一个新网页,但是,我不知道如何访问新网页我还希望在创建时显示新创建的网页的链接,例如使用之前.在js中显示我的时钟按钮之前的动态功能.

click

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 = "

new website";

xmlhttp.open("GET","makePage.php?content=" + content,true);

xmlhttp.send();

}

PHP

$content = $_GET["content"];

$file = uniqid() . ".html";

file_put_contents($file, $content);

echo $file;

?>

有什么建议?我可以阅读的指导或相关页面.一切都将非常感激.

解决方法:

在你的js做这样的事情而不是警报:

if(xmlhttp.readyState==4 && xmlhttp.status==200){

var createA = document.createElement('a');

var createAText = document.createTextNode(xmlhttp.responseText); // or whatever name you need

createA.setAttribute('href', xmlhttp.responseText);

createA.appendChild(createAText);

document.body.appendChild(createA); // or you can create some

or whatever and append it to that

}

这是普通的javascript,但使用jquery,您可以使用ajax或get函数轻松完成.

标签:php,javascript,ajax,html

来源: https://codeday.me/bug/20190702/1354447.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值