用ajax发布数据

I'm trying to save a few lines of text in a textarea with ajax targeting a classic asp file.

I'm not sure how to use ajax when when it comes to sending data with POST method and NOT using jQuery, didn't find any questions concerning this here either, no duplicate intended.

Ajax function:

function saveDoc() {//disabled
var xhttp = new XMLHttpRequest();
var note = document.getElementById("note");

xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        document.getElementById("0").innerHTML = xhttp.responseText;
    }
};
xhttp.open("POST", "saveNote.asp", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(note);

ASP Classic:

set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile("c:\inetasp\1.txt",8,true)

dim note

note = RequestForm("note")
f.Write(note)
f.Close
Response.Write("Works.");

set f=nothing
set fs=nothing

I'm aware there might be a lot wrong with the .asp since i couldn't find any specific info about how to handle ajax requests with Classic ASP correctly.

Any suggestions on how to make this work without jQuery are welcome.

I cannot test your code as I don't have a backend running on my machine right now. But I can already tell you a few things:

  • you are calling xhttp.send(note); but your note is a DOM element. It should be a string with a querystring format.
  • in your server side code you call RequestForm is it a custom function you have previously defined ? The usual syntax is Request.Form

Hope it can help