I've written the following Javascript code:
function sendCcbRequest(text) {
var jsonToSend = "\"text\": \"" + escape(text) + "\"";
$.ajax({
type: "POST",
url: 'x.asp',
data: jsonToSend,
success: function(response) {
alert("success:" + response);
},
error: function() {
alert("error");
}
}); // end ajax
}
How do I read the data that I post from my classic ASP code?
Update I've tried the following for my classic asp file x.asp.
<%
Dim x
x = Request.Form("text")
Response.Write(x)
%>
It still prints nothing.
The way the data is posted using this method (as posted in the question) doesn't really create a form object on the server side. So the posted data is to be read using Request.BinaryRead and then converted to string using one of the methods given here. As you have already noted, if you send the data using query string form key1=value1&key2=value2 or a map of the form {key1: 'value1', key2: 'value2'}, the posted data is a valid form and ASP would convert it to a Request.Form that can be read much easily.
Okay, I've found something that works. The following line of code:
var jsonToSend = "\"text\": \"" + escape(text) + "\"";
needs to be changed to
var jsonToSend = { text: escape(text) };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With