weixin_33725270 2018-11-13 18:46 采纳率: 0%
浏览 50

将输入发送到Ajax中的文件

I want to put the code in the textarea's as below and send it to a file and I do not know Ajax I understand it but can't write.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Testing</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="main.js"></script>
</head>
<body>
    <textarea id="html"></textarea>
    <textarea id="js"></textarea>
    <textarea id="css"></textarea><br>
    <input type="button" value="Run" id="run">
    <iframe src="example.html" frameborder="0"></iframe>
    <button onclick="loadDoc()">Try The Ajax</button>
</body>
</html>

The contents of main.js are:

function loadDoc() {
    var fred = document.getElementById("js");
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("html").innerHTML =
                this.responseText;
        }
    };
    xhttp.open("GET", "example.html", true);
    xhttp.send();
}

It loads but will not send. I have tried xhttp.send(fred, "example.html",true) but it did not work. So abit like codepen or jsfiddle

  • 写回答

1条回答 默认 最新

  • weixin_33719619 2018-11-13 19:04
    关注

    Ajax is the act of making an HTTP request from JavaScript without leaving the page.

    It cannot write to files.

    You can make an HTTP request to a URL which is handled by server-side code that uses information in the request to write to a file (although it is more usual to write to a database).

    Pick a programming language you like and look up an introductory tutorial for server-side programming using it.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘