We help IT Professionals succeed at work.

Phonegap on server computer need response thru asp.

Whing Dela Cruz
on
High Priority
118 Views
Last Modified: 2019-11-13
I run the code below thru PhoneGap, http://192.168.1.7:3000 but I've found out that the Asp on server computer ignored the request. Here, I would like to know if the PhoneGap has a capacity to allow the server accept the request from the clients via phonegap apps? The code below is working if i used iis. Any help please.. Thanks!

    <script>
    function GetSerialDrive()
    {
    	if (window.XMLHttpRequest)
    	  {// code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp = new XMLHttpRequest();
    	  }
    	else
    	  {// code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	xmlhttp.onreadystatechange=function()
    	  {
    	  if (this.readyState==4 && this.status==200)
    	    {
                alert(this.responseText);
    	    }
    	  }                                             
    		xmlhttp.open("GET","MyDrive.asp?a=" + "x", true);
    		xmlhttp.send();	
    }
    </script>

Open in new window

 

Server side
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
   response.write("The serialnumber is " & d.SerialNumber)
   response.end()
set d=nothing
set fs=nothing
%>

Open in new window

Comment
Watch Question

Scott FellDeveloper & EE Moderator
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
remember, your front end code is on a device not associated with the server. This means your get request should be to the full url https//mysite.com/page.asp.

Also, a phone is going to have a modern browser. Some of your is code contains options that no longer are needed

Author

Commented:
Hello Scott Fell, Can you tell me what is the best way to communicate with the server using Phonegap?
Developer & EE Moderator
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013
Commented:
Phonegap/cordova is just the client/front end.

In classic ASP you would have a page like this
<% 
   x = "Hello World"
%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>My App</title>
</head>
<body>
  <% response.write x%>
</body>
</html>

Open in new window


Anything inside of the asp tags <% %> gets processed on the server before the page loads. Once the page loads, you can view the source and see that only the rendered html/css/js is available.  With phonegap (or native application), the page that is being loaded is not on your server and is instead in the custody of the user. This means that any of the code in the asp tags will not get run. Instead, you will use all front end code in javascript.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>My App</title>
  <script>
    document.addEventListener('DOMContentLoaded', function(){
      
    var results = document.getElementById('results');
    results.innerHTML = 'Hello World';
});
  </script>
</head>
<body>
  <div id="results"></div>
</body>
</html>

Open in new window


The examples above are using hard coded data. You want your data to come from your own database. To do that, you would just replace this line
var results = document.getElementById('results');

Open in new window

with your xmlhttp request similar to above. Keep in mind you don't have to worry about old browsers and you do have to worry about cross site scripting https://developer.chrome.com/apps/xhr. The security and how to do this would be best for separate question.

Author

Commented:
Thanks a lot Scott Fell, I believed that this guide will lead me to solve the problem..

Explore More ContentExplore courses, solutions, and other research materials related to this topic.