• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1065
  • Last Modified:

Need Help Interpreting responseText Message from XMLHTTP Object

Hello,

I am running ASP Classic on a Win 2008 R2 server.

I have code as follows:

Set xml = Server.CreateObject("Microsoft.XMLHTTP") url="http://www.myvendor.com/subfolder1/subfolder2/pagename.php?"
url=url & params
xml.Open "GET",url,False
xml.Send
calltext=xml.responseText
Set xml = Nothing

In the above, params is a conventional querystring (e.g., aaa=111&bbb=222&ccc=333).

calltext, which contains the AJAX responseText, contains the correct response information when printed into a web page or system generated email.

But I cannot perform any logic on calltext.  For example, if calltext contains "SUCCESS" as printed out on a web page or automated email, and I try logic like:

<%if calltext="SUCCESS" then
    'success logic
else
    'failure logic
end if%>

the failure logic gets executed.

I contacted the vendor (the owner of the system I am making the AJAX call to), and they confirmed that they are not performing any conversions of the responseText from ASCII to another encoding scheme.

Does anyone have any ideas?  Maybe the responseText property of the XMLHTTP object is not natively in string format, and I need to perform some kind of conversion before ASP Classic can interpret responseText correctly.

Thanks very much,
Stu Engelman
0
stuengelman
Asked:
stuengelman
  • 9
  • 7
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
Stu,
Do you know what the actual response is?

what happens if you do a

<%response.write calltext%>

Let's see the type of response.  Is it text, html, json, xml....
0
 
Scott Fell, EE MVEDeveloperCommented:
You may have to parse through the json or xml is whats I am getting at.  If it is just text, try  if

if trim(calltext)="SUCCESS" then

or
if instr(1,trim(calltext), "SUCCESS",1)>0 then
  'your good
  else
  'no way
end if
0
 
stuengelmanAuthor Commented:
Hi Padas,

I've tried cstr(calltext) and trim(cstr(calltext)), both to no avail in the ASP if/then logic.

<%response.write calltext%> results in normal ASCII (the correct, expected readable text with ASCII hex encoding).

Stu
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
Scott Fell, EE MVEDeveloperCommented:
What is the exact  text you get when you response.write calltext? Please run this and view source and copy and paste from viewing source, not the what you see in your browser.  

I doubt you are getting simply, "SUCCESS".  Or maybe that is just what you see in the browser but it is really wrapped in json or xml which needs to be parsed.

fyi, cstr is for converting to text.  So if you are expecting text, no need to use cstr.  I used trim to remove white space to the left and right so " SUCCESS " becomes "SUCCESS".  I used instr, not cstr in order to search if the string exists.
0
 
stuengelmanAuthor Commented:
Hi Padas,

response.write calltext results in the exact text "TEST_SUCCESS" (without the quotes).  This is the value I am testing against this in my code (not "SUCCESS" as in my sample code mentioned earlier).

I'll try your syntax (if instr(1,trim(calltext), "TEST_SUCCESS",1)>0 then) to see if that works.

"TEST_SUCCESS" is the successful responseText for my vendor's debug mode operation (i.e., the querystring format is tested for syntax accuracy, but no data is posted to their system).  When you go into live mode, the successful responseText is "SUCCESS".  A concern I have is that if any failure responseText values contain "SUCCESS", such as "NOT SUCCESSFUL - INVALID USERNAME", your method will invoke my success logic.  Is there any test I can use to determine the precise responseText?

Stu
0
 
stuengelmanAuthor Commented:
Hi Padas,

I tried the syntax: if instr(1,trim(calltext),"TEST_SUCCESS",1)>0 then

The failure logic executed, even though "TEST_SUCCESS" was certain to be the result (I didn't change my querystring).

It appears this syntax does not solve the problem.

Stu
0
 
Scott Fell, EE MVEDeveloperCommented:
I'm going to ask for the 3rd time....!!  VIEW THE SOURCE after you get the response  ;)
You are probably not getting straight text as output.  My guess is you are getting xml and we need to  parse the xml.   When you view source - pelase copy and paste the response.  Or better yet, can you point a link to the web service you are using so we can see what the response is supposed to be.

<%
Set xml = Server.CreateObject("Microsoft.XMLHTTP") url="http://www.myvendor.com/subfolder1/subfolder2/pagename.php?"
url=url & params
xml.Open "GET",url,False
xml.Send
calltext=xml.responseText
Set xml = Nothing
' PUT CODE TO READ THE XML RESPONSE HERE
  'http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_27800798.html

  'read xml node for response
  'theResponse=what_is_in_the_xml_node

MODE="Test"  'Test or Live
if MODE="Live" then
   if theResponse="SUCESS" then
       ' do stuff
   end if

else

    if theResponse="TEST_SUCCESS" then
        'do some test stuff
    end if

end if
%>

Open in new window

0
 
stuengelmanAuthor Commented:
Hi Padas,

Forget my last post; I forgot to upload the code after changing it.  Your syntax does in fact solve the problem.  I'm certain the responseText is not in XML format (no parsing is necessary) as I've printed it out using response.write and it just says "TEST_SUCCESS" (without the quotes) without any XML structure tags.

But I still have the issue I mentioned earlier: if any failure responseText values contain "SUCCESS", such as "NOT SUCCESSFUL - INVALID USERNAME", your method will invoke my success logic.  Is there any test I can use to determine the precise responseText?

Thank you, Stu
0
 
Scott Fell, EE MVEDeveloperCommented:
as I've printed it out using response.write and it just says "TEST_SUCCESS" (without the quotes) without any XML structure tags.
Did you view the source?  XML written inside of xml will not look like xml in the browser.  You have to view the source.  The actual response might be <response>SUCCESS</response> but you can't see the tags.  Actually, the response would be larger then that but you just see, SUCCESS.   This would be the reason you can't use if calltext="SUCCESS" then but you can use if instr(1,trim(calltext), "SUCCESS",1)>0 then

if you don't want to parse the xml you could do

dim ok
ok=0
if instr(1,trim(calltext), "SUCCESS",1)>0  then ' possible
   if instr(1,trim(calltext), "NOT SUCCESSFUL",1)=0 then ' yes
       ok=1
   end if
end if
if ok=1 then
   'do stuff because your happy it went through
   else
   'do something else because you need to say something
end if
0
 
stuengelmanAuthor Commented:
Hi Padas,

I follow what you're saying.  I sent an email to the vendor asking whether the word SUCCESS appears in any failure values.  If not, I am all set.  Otherwise, I can check for "false positives" using your technique by getting a list of all operant exceptions from the vendor.

Thanks so much - great job!

Stu
0
 
stuengelmanAuthor Commented:
Excellent job.  Simple solution and fully solved problem.
0
 
Scott Fell, EE MVEDeveloperCommented:
Awesome!  

I'm still curious if you are getting an xml response as you have, "calltext=xml.responseText"
0
 
stuengelmanAuthor Commented:
Hi Padas,

I don't know whether the responseXML property is being populated by the vendor.  I am using the responseText property in my code as I am certain they are populating that.

As mentioned earlier, I did print calltext to both a web page and an automated email, and it displayed without XML tags.  I also copy/pasted the web page output into an ASCII-to-hex converter, and it had exactly the same hex as hand-typed "TEST-SUCCESS".  It's possible that response.write(calltext) might strip any XML tags out in web output, but I doubt placing calltext in an email body would do this.  My best guess at this point is that xml.responseText has unprintable and invalid ASCII hex at the start or end.

At any rate, the vendor confirmed that no failure return values contain SUCCESS embedded anywhere.  So I don't have to code for any "false positive" exceptions.

I just switched from debug to live mode, and am waiting for the vendor to send me a screen shot so I can tell whether or not they captured all my querystring values correctly.  I'll shoot you another message to let you know how this went.

Thanks so much for all your great help.

Stu
0
 
stuengelmanAuthor Commented:
Padas,

Live test lead posted perfectly to the vendor system.

We're set to do business!!

Stu
0
 
Scott Fell, EE MVEDeveloperCommented:
It's possible that response.write(calltext) might strip any XML tags out in web output
No.  However, as I have said, when the response comes back as xml which it probably does and you do a response.write of that xml inside of the browser where you have the doctype set as html and it is inside of other <html> tags, you will not see xml in the browser. It will look like plain text. However, if you VIEW SOURCE you will probably see output like  below.  If you place this code inside of your html you will just see

Hello World!  ERROR  S0015  R0006

But viewing the browser source you see

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <soap:Envelope xmlns:soap="…">
      <soap:Body>
        <sms:sms xmlns:sms="hellip;">
          <sms:sentsms>
            <sms:phone>0821234567</sms:phone>
            <sms:message>Hello World!</sms:message>
            <sms:status>ERROR</sms:status>
            <sms:id>S0015</sms:id>
          </sms:sentsms>
          <sms:newsms>R0006</sms:newsms>
        </sms:sms>
      </soap:Body>
    </soap:Envelope>

Open in new window


What your code is doing with instr is looking throw all the xml for "Success" when you could  just parse out the response.  

I could be wrong though.  

I'm glad you have this working.
0
 
stuengelmanAuthor Commented:
Hi Padas,

I did view the source code in MSIE after performing response.write(calltext), and all it had was TEST_SUCCESS.  Since I verified that the ASCII hex was correct, my best guess at this point is that invalid hex precedes or follows the responseText from the AJAX object.

Thanks again, Stu
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now