I am having a bit of trouble retrieving variables from an ASP page. It returns the entire page whereas I just need the variable strAnswer from the page. Please help?
Here is my code:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onDataSaved);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
var request:URLRequest = new URLRequest("http://" + host + urlPath + "setXML.asp");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.xmlString = str;
variables.eltGuid = eltGuid;
request.data = variables;
loader.load(request);
private function onDataSaved(e:Event):void
{
var loader2:URLLoader = URLLoader(e.target);
loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
trace(loader2.data.strAnswer);
}
ASP Page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>setASP</title>
</head>
<body>
<%
Dim xmlBlock, strEltGuid, objRQL
xmlBlock = escape(Request.Form("xmlString"))
strEltGuid = Request.Form("eltGuid")
'---------------------------
'Post to RedDot CMS via RQL
'---------------------------
Set objRQL = Server.CreateObject("RDCMSASP.RdPageData")
objRQL.XMLServerClassname = "RDCMSServer.XmlServer"
xmlData = "<IODATA loginguid=" & Chr(34) & Session("LoginGuid") & Chr(34) & " format=" & Chr(34) & "1" & Chr(34) & " sessionkey=" & Chr(34) & Session("SessionKey") & Chr(34) & "><ELT translationmode='0' extendedinfo='' reddotcacheguid='' action='save' guid='" & strEltGuid & "' pageid='' id='' index='' type='31'>" & xmlBlock & "</ELT></IODATA>"
'Response.Write(xmlBlock)
'Response.Write(strEltGuid)
objRQL.ServerExecuteXML xmlData, rqlError
If rqlError <> "" Then
Response.Write rqlError
Else
strAnswer = "strResponse=Just a test! How strange. ..."
Response.Write (strAnswer)
'Response.Write "strResponse=Just a test! How strange. ..."
'Response.Write "Saved successfully." '"Saved successfully." '
End If
'Response.Write "strResponse=Just a test! How strange. ..."
'------------------
'Be a good citiz开发者_开发知识库en
'------------------
Set objRQL = Nothing
%>
</body>
</html>
You are creating and loading an html page. If you remove all of the html tags and just use Response.Write to output the variable, that should work.
I used to do this a lot in the past to load dynamically generated XML from ASP into Flash. I have blog post about this here: http://www.herrodius.com/blog/18
精彩评论