I've written the following Javascript code:
我已经编写了以下Javascript代码:
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?
如何读取我从经典的ASP代码中发布的数据?
Update I've tried the following for my classic asp file x.asp.
更新我尝试了以下经典的asp文件x.asp。
<%
Dim x
x = Request.Form("text")
Response.Write(x)
%>
It still prints nothing.
它仍然打印。
4 个解决方案
#1
4
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.
使用这个方法(如问题中提到的)发布数据的方式并没有在服务器端创建一个表单对象。因此,要使用Request读取已发布的数据。BinaryRead然后使用这里给出的方法转换为字符串。正如您已经注意到的,如果您使用查询字符串形式key1=value1&key2=value2发送数据,或者使用表单{key1: 'value1' key2: 'value2'}发送数据,则发布的数据是有效的表单,ASP会将其转换为请求。可以很容易阅读的表格。
#2
3
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) };
#3
0
I would use the parser described here: Any good libraries for parsing JSON in Classic ASP? . It's worked for me.
我将使用这里描述的解析器:在经典ASP中解析JSON有什么好的库吗?。它为我工作。
#4
0
From the x.asp
page, simply use: Request.Form("text")
to read the text that your Ajax request posted.
从x。asp页面,简单地使用:request . form(“text”)来读取Ajax请求发送的文本。
#1
4
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.
使用这个方法(如问题中提到的)发布数据的方式并没有在服务器端创建一个表单对象。因此,要使用Request读取已发布的数据。BinaryRead然后使用这里给出的方法转换为字符串。正如您已经注意到的,如果您使用查询字符串形式key1=value1&key2=value2发送数据,或者使用表单{key1: 'value1' key2: 'value2'}发送数据,则发布的数据是有效的表单,ASP会将其转换为请求。可以很容易阅读的表格。
#2
3
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) };
#3
0
I would use the parser described here: Any good libraries for parsing JSON in Classic ASP? . It's worked for me.
我将使用这里描述的解析器:在经典ASP中解析JSON有什么好的库吗?。它为我工作。
#4
0
From the x.asp
page, simply use: Request.Form("text")
to read the text that your Ajax request posted.
从x。asp页面,简单地使用:request . form(“text”)来读取Ajax请求发送的文本。