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.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料