经典ASP-无法从AJAX发布请求获取Request.Form值 [英] Classic ASP - Cannot Get Request.Form Values from AJAX Post Request
问题描述
我有一个脚本,该脚本通过AJAX提交表单的POST请求.
I have a script that is submitting a POST request of a form via AJAX.
当我查看网络"选项卡时,它以下面的格式返回,我无法使用Classic ASP中的标准 Request.Form
来阅读.由于AJAX请求,我还看到此服务器变量也添加到了页面请求中: HTTP_X_REQUESTED_WITH
= XMLHttpRequest
When I look at the network tab, it is coming back in the format below, which I cannot read with a standard Request.Form
in Classic ASP. I am seeing this server variable added to the page request as well due to the AJAX request: HTTP_X_REQUESTED_WITH
= XMLHttpRequest
将表单设置为简单的POST:< form method ="post"action ="/contact-submit">
The form is set up as a simple POST: <form method="post" action="/contact-submit">
我无法更改执行AJAX请求的脚本来更新内容类型等.
I cannot change the script performing the AJAX request to update the content type, etc.
这是下面网络"标签上响应中的请求有效负载".我已经用Google搜寻了好几天,无法解决这个问题.您如何访问这些数据?我什至尝试使用通过ASPUpload拥有的文件上传脚本来读取它,但是 Upload.Form("contact_name")
也不起作用,它也是空白.
This is the "Request payload" in the response on the network tab below. I have googled for days and cannot figure this out. How do you access this data? I even tried reading it with a file upload script I have via ASPUpload, but Upload.Form("contact_name")
does not work either, it's blank as well.
我尝试了一个简单的PHP脚本(我不知道PHP的工作方式,但是该脚本与执行POST作为演示的脚本一起提供),然后调用 print_r($ _ POST)
脚本将所有返回网络"选项卡上的响应中的数组中的正确信息.哎呀!
I tried a simple PHP script (I do not know how PHP works, but this script came with script performing the POST as a demo), and calling print_r($_POST)
the script passes all the correct info in an array back in the response on network tab. What the heck!!
有人知道如何在Classic ASP中取回这些数据吗?
Does anyone know how to get this data back in Classic ASP?
非常感谢您的提前帮助.
Thanks so much for the help in advance.
丹尼斯
-----------------------------254001430938683980861095915686
Content-Disposition: form-data; name="contact_name"
Test Name
-----------------------------254001430938683980861095915686
Content-Disposition: form-data; name="contact_email"
test@test.com
-----------------------------254001430938683980861095915686
Content-Disposition: form-data; name="contact_message"
my message
-----------------------------254001430938683980861095915686--
推荐答案
我正在研究一种读取数据的解决方案,该方法在下面起作用.不确定这是最好/最便宜的方法,但是它有效!
I worked on a solution to reading the data, this works below. Not sure it is the best / least expensive way to do this, but it works!
感谢大家的帮助/提示.如果有人有更好的方法来解析上面的响应,我会很::
Thanks to everyone for the help / tips. If anyone has a better way to parse the response above, I'm all ears :)
<%
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "iso-8859-1"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
If Request.TotalBytes > 0 Then
Dim lngBytesCount, post
lngBytesCount = Request.TotalBytes
post = BytesToStr(Request.BinaryRead(lngBytesCount))
End If
Response.ContentType = "text/plain"
sContentType = Replace(Request.ServerVariables("CONTENT_TYPE"),"multipart/form-data; boundary=---------------------------","")
arrPost = Split(post,"-----------------------------" & sContentType)
For i = 0 to UBound(arrPost)
sVal = Replace(arrPost(i),"Content-Disposition: form-data; name=","")
arrVal = Split(sVal,Chr(10),1)
For a = 0 to UBound(arrVal)
If Instr(1, arrVal(a), "contact_name") <> 0 Then
Response.Write GetValue(arrVal(a), "contact_name")
End If
If Instr(1, arrVal(a), "contact_message") <> 0 Then
Response.Write GetValue(arrVal(a), "contact_message")
End If
Next
Next
Function GetValue(f_FullString, f_FieldName)
fieldval = Replace(f_FullString, """" & f_FieldName & """","")
'response.Write "_" & fieldval & "_<Br>"
arrVal1 = Split(fieldval,Chr(10),1)
For b = 0 to UBound(arrVal1)
newval = arrVal1(b)
newval = Left(newval,Len(newval) - 2)
newval = Right(newval,Len(newval) - 6)
'For z = 1 to Len(newval)
' CurrChar = Mid(newval, z, 1)
' Response.Write Asc(CurrChar) & "<bR>"
'Next
Next
GetValue = newval
End Function
%>
更新:
如果已安装ASPUpload,则这是另一种解决方案.我昨晚尝试了此操作,但忘了添加Upload.Save(这可以为我节省4个小时的工作--- UGGGGGHHHH).
This is another solution if you have ASPUpload installed. I tried this last night, but forgot to add Upload.Save (which would have saved me 4hours of work --- UGGGGGHHHH).
'http://www.aspupload.com/manual_memory.html
Set Upload = Server.CreateObject("Persits.Upload")
Upload.Save
Name = Upload.Form("contact_name")
Response.Write Name
这篇关于经典ASP-无法从AJAX发布请求获取Request.Form值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!