[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

Function return type mismatch

Experts,

Please help.  I am trying to get result from a javascript function, but it is giving me type mismatch error.  Please help.  Here is the code, please give me the correctcode.

function fetchAcct()
{
      //theUID = window.prompt ("User ID","Enter the UserID to search for");
      theUID = "12345"
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      xmlhttp.open ("GET", "http://findacct.com/FindResults.asp?t=1&k=" + theUID, false);
      xmlhttp.send();
      foo = xmlhttp.responseText;
return foo;
}

I  gave a alert to check the foo.  I am not even getting the alert.  How do I call this function and get the return value ?
0
suran78
Asked:
suran78
  • 7
  • 5
1 Solution
 
BatalfCommented:
The best advice I can give is that you download a more crossbrowser version of XMLHTTP. A good one is available at

http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/

Your function could be rewritten to this:

function fetchAcct()
{
     //theUID = window.prompt ("User ID","Enter the UserID to search for");
     theUID = "12345"
     var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          foo = xmlhttp.responseText;          
        }
      }
     xmlhttp.open ("GET", "http://findacct.com/FindResults.asp?t=1&k=" + theUID, false);
     xmlhttp.send();
     return foo;
}

i.e. with an onreadyState event. I have never used XMLHTTP in a function which should return data from the request. I'm not sure how well it would work if the script(FindResult.asp) takes some time.

Batalf
0
 
suran78Author Commented:
Thanks for replying,  I tried your code.  I am getting this error when I am just calling this function in asp page as fetchAcct()

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'fetchAcct'
/ePMO/conn.asp, line 67
0
 
BatalfCommented:
VBScript runtime - How is your <script> tag?

It should be like this:

<script type="text/javascript">

and not

<script language="VBScript">

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
suran78Author Commented:
Still getting the error.  Don't know why ? This is how I have:

<html>
<head>
<title>Users</title>
<script type="text/javascript">

function fetchAcct()
{
     //theUID = window.prompt ("User ID","Enter the UserID to search for");
     theUID = "12345"
     var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          foo = xmlhttp.responseText;          
        }
      }
     xmlhttp.open ("GET", "http://findacct.com/FindResults.asp?t=1&k=" + theUID, false);
     xmlhttp.send();
     return foo;
}

</script>
</head>
<body>
....
<%fetchAcct()%>
</body>

0
 
suran78Author Commented:
I am getting the type mismatch on

<% fetchAcct() %>

Maybe I am not calling it corretly ?
0
 
BatalfCommented:
Do you have to call the function from Vbscript?

Could you change

<%fetchAcct()%>

to

<script type="text/javascript">
fetchAcct();
</script>

?
0
 
suran78Author Commented:
I changed it to javascript just to see it it's working.  The good news is that I am not getting any error the bad news is I am not gettting anything. I added a alert foo inside the function and got error.  How can i see what the function is returning ?

Later I have to call it the fetchacct in vb


0
 
suran78Author Commented:
The findresult site work for sure, so that'snot teh problem here.  This is the function again.  Is there any mistake ?

function fetchAcct()
{
     //theUID = window.prompt ("User ID","Enter the UserID to search for");
     theUID = "77480"
     var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          foo = xmlhttp.responseText;          
        }
      }
     xmlhttp.open ("GET", "http://findacct.com/FindResults.asp?t=1&k=" + theUID, false);
     xmlhttp.send();

     return foo;
}
0
 
BatalfCommented:
I'm not that familiar with VBSCript, but I guess it would be something like

<%call fetchAcct()%>

or

<%call fetchAcct%>

For testing purpose, modify your function to this:

function fetchAcct()
{
     //theUID = window.prompt ("User ID","Enter the UserID to search for");
     theUID = "12345"
     var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          foo = xmlhttp.responseText;  
          alert(foo);      
        }
      }
     xmlhttp.open ("GET", "http://findacct.com/FindResults.asp?t=1&k=" + theUID, false);
     xmlhttp.send();
     return foo;
}
0
 
suran78Author Commented:
When I am going to this site with uid 1234, directly(not thru xmlhttp), I am getting result.  But with xmlhttp - I am getting the alert msg and it is giving blank result. Is it not submitting the uid to the findresult page thru xmlhttp ?
0
 
suran78Author Commented:
Oh!  see whats happeneing the alert window is long and is not fitting the screen.  and it is not allowing me to see the result.  It's also not scrollable.  
0
 
BatalfCommented:
What does FindResult.asp return?
0
 
jessegivyCommented:
I'd be inclined to agree that you are not returning a value from FindResult.asp or rather that it is returning an empty string and that's why you don't see anything.  Focus on making sure that the asp page is returning a value that isn't empty
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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