[英]Send an Array with Ajax and receive it in ASP Classic page
I need to pass an array with AJAX in a ASP page. 我需要在ASP页中使用AJAX传递数组。
I tried passing it as GET to see the data that it sends and i noticed that the ASP receive only the LAST record of the array. 我尝试将其作为GET传递,以查看其发送的数据,并且我注意到ASP仅接收数组的LAST记录。
How can i send and receive the whole array? 我如何发送和接收整个阵列? (preferably with POST method)
(最好使用POST方法)
Javascript Java脚本
function editar(i) {
arr=[];
j=0;
for (n=2; n<=9; n++) {
arr[j]=$("#"+i+"-"+n).val(); //saves in the array all the field of a table's row
}
$.ajax ({
url:"page.asp",
data: { arr:arr },
type:"POST"
}).done(function(msg){
alert(msg)
})
}
ASP page.asp ASP page.asp
<%
redim arr(10)
for i=0 to 9
arr(i)=request.Form("arr[]") 'Tried without the square brackets too
next
%>
An html form doesn't have an array data structure. html表单没有数组数据结构。 In fact, an html form doesn't really have data types: pretty much everything you put into a form will come back out as a string.
实际上,一个html表单实际上并没有数据类型:几乎您放入表单中的所有内容都会以字符串形式返回。 So your best bet is probably to write the array into a string (via
.join()
), which you can then parse on the other end (using, eg Split()
). 因此,最好的选择是将数组写入字符串(通过
.join()
),然后可以在另一端进行解析(使用例如Split()
)。
Keeping in mind that I'm terrible at JavaScript, I think you'd do something like 请记住,我在JavaScript方面很糟糕,我认为您会做类似的事情
data: { 'arr':arr.join('+++') }
and then in your VBScript, you'd do 然后在您的VBScript中
dim arr '- note that you're NOT dimming as an array
arr = Split(Request.Form("arr"),"+++")
Note that in practice, whenever I use Split, I add a delimiter to the end, just to make sure that Split won't throw an error. 请注意,实际上,每当我使用Split时,我都会在末尾添加一个定界符,以确保Split不会引发错误。
const delimiter = "+++"
arr = Split(Request.Form("arr") & delimiter,delimiter)
function editar(i) {
arr=[];
j=0;
for (n=2; n<=9; n++) {
arr[j]=$("#"+i+"-"+n).val(); //saves in the array all the field of a table's row
}
$.ajax ({
url:"page.asp",
data: { 'arr[]':arr },
type:"POST"
}).done(function(msg){
alert(msg)
})
} }
i had to change your "arr" in the data object to 'arr[]' and that will do 我不得不将数据对象中的“ arr”更改为“ arr []”,这将
use the snippet below on the server side C# 在服务器端C#上使用下面的代码段
string[] values = Request.Form.GetValues("arr[]");
Vb Vb
Dim values As String() = Request.Form.GetValues("arr[]");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.