How can I update webpage data (javascript variable) by email post

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tgmcnaughton
    New Member
    • Aug 2007
    • 6

    How can I update webpage data (javascript variable) by email post

    I have a javascript running on a page hosted by googlepages at:
    http://tgmcnaughton.go oglepages.com/map2.htm
    It uses the google map api to draw a map and plot a marker at a particular latitude and longitude.

    I have a GPS device which sends emails to my gmail account which contain new latitude and longitude coords. I want to periodically check for new messages from the sender (or ideally respond to a "You've got mail message") and update the two variables in the javascript:

    What language would be used for this kind of thing? It seems to me that it is in the same class of problem as emailing direct to a blog.

    Of course the sender's name is fixed eg: xxx@airmessage. net and the dataformat is fixed. I just need to know how to get programmatic access to the email message.

    Does this constitute server-side scripting? If JavaScript cannot do this, then what language would I use?
    Thanks very much,
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    so if I understand you right, you have a form of some kind which a user will fill out and hit a submit button. The submit sends an email which alerts you of potential changes to some data. You would like to review the data in your email and then click some kind of "accept changes" button? If the data is fairly simple, it might be best to have a link in the email body with extensive querystring data:[html]<a href="mySite.co m/updater.asp?lon g=12deg45min17s ec&lat=75deg16m in43sec&update= true">Click here to update</a>[/html] then the actual changes will have to be handled on the updater.asp page. Does this help?

    Jared

    Comment

    • tgmcnaughton
      New Member
      • Aug 2007
      • 6

      #3
      Originally posted by jhardman
      so if I understand you right, you have a form of some kind which a user will fill out and hit a submit button.
      Jared
      ...
      not quite... Let me try to explain a bit better:

      The application is a simple GPS tracker. The elements are a device that combines a GPS chipset and a 2-way programmable alphanumeric pager. The pager can send a string in which its current latitude and longitude coordinates are encoded. I have it set to automatically send pages every 5 minutes whenever it is moving. The pages are automatically processed by the pager network service, converted and sent on as emails. I then get an email in my gmail account with a body containing a string like:

      A3402.40611712. 29122514400

      which means:
      Lat:34deg 02.40min
      Long: -117deg 12.291min
      time stamp: 22:51:44

      So that's the source of the data. There are no forms or submit buttons or really any user input at all on this side.

      At the webpage, there is a Javascript page with the following code:
      http://tgmcnaughton.go oglepages.com/map2.htm

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
          <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
          <title>Google Maps JavaScript API - tgm version 1.0</title>
          <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg"
                  type="text/javascript"></script>
          <script type="text/javascript">
          //<![CDATA[
      
      	var lat = 34.232487;
      	var lon = -117.247165;	
      	var point = new GLatLng(lat,lon);
      
          function load() {
            if (GBrowserIsCompatible()) {
      		var map = new GMap2(document.getElementById("map"));
              	map.setCenter(new GLatLng(lat,lon), 13);
      		map.addControl(new GSmallMapControl());
      		map.addControl(new GMapTypeControl()); 	
      		map.addOverlay(new GMarker(point));
            }
          }
      
          //]]>
          </script>
        </head>
      
        <body onload="load()" onunload="GUnload()">
          <div id="map" style="width: 800px; height: 500px"></div>
        </body>
      </html>
      I want to replace line 12 and 13 with code that will do the following:

      login to my gmail account
      find the latest email message
      open the message
      copy the bodytext into a string variable.
      parse the string into lat and lon and time
      update the two variables lat and lon with the current position of the pager.

      Remember, the gmail account is just continuously receiving updates with new location strings. When the page is accessed, I want it to automatically go out and get an updated location.

      Does this make sense?

      Thanks,
      Tim

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Tim,

        yes, that makes sense, but it's a bit beyond me. Let me ask a hypothetical question: Is there any chance you could change the email address to which the mail is sent or if not, can they be forwarded to another address? If these went to a non-encrypted email address it would probably be easier. ASP can be used to open email, but I think it really only works well if the mail file is already on that server. I've never had a system set up that way, so I've never been in a position to test it. Then updating those variables are really easy. If you are interested in checking into it, I'm willing to help.

        Jared

        Comment

        • tgmcnaughton
          New Member
          • Aug 2007
          • 6

          #5
          Originally posted by jhardman
          Tim,
          Is there any chance you could change the email address to which the mail is sent
          Jared
          Yes, I can set the email address to whatever. I was sending to my gmail account (the webpage is hosted at googlepages).

          It seems to me that what is needed is the same sort of method that is used to allow someone to email directly into their own blog. I have set up a blog at blogger.com and have been having the device send its email there. The site allows you to specify a "Mail-to-Blogger Address."
          Any emails sent there are added as posts on the blog.
          You can see the result at: tgmtrack.blogsp ot.com.
          I like your idea of keeping everything on one server. I'm very glad to have your help with this. I have never used ASP before.
          Thanks,
          Tim

          Comment

          • tgmcnaughton
            New Member
            • Aug 2007
            • 6

            #6
            I got to thinking, maybe it's easier to email the coordinates into my publicly accessible blog at http://tgmtrack.blogspot.com/ (like I'm doing now) and then have the javascript at http://tgmcnaughton.googlepages.com/map2.htm
            go out and extract the data from the blog. This might avoid the security issues inherent in logging into a remote email account.

            I found a relevant tutorial at: http://classicasp.aspfaq.com/general...-web-page.html. It includes the following snippet.
            Code:
            <script language=javascript runat=server> 
                var url = "http://www.espn.com/main.html"; 
                var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP"); 
                xmlhttp.open("GET", url, 0); 
                xmlhttp.send(""); 
                Response.Write(xmlhttp.responseText); 
                var xmlhttp = null; 
            </script>
            I tried it but it doesn't work on my page at google pages. Maybe googlepages doesn't support ActiveXObjects?

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              Originally posted by tgmcnaughton
              I got to thinking, maybe it's easier to email the coordinates into my publicly accessible blog at http://tgmtrack.blogspot.com/ (like I'm doing now) and then have the javascript at http://tgmcnaughton.googlepages.com/map2.htm
              go out and extract the data from the blog. This might avoid the security issues inherent in logging into a remote email account.
              that sounds like a good idea to me
              Originally posted by tgmcnaughton
              I found a relevant tutorial at: http://classicasp.aspfaq.com/general...-web-page.html. It includes the following snippet.
              Code:
              <script language=javascript runat=server> 
                  var url = "http://www.espn.com/main.html"; 
                  var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP"); 
                  xmlhttp.open("GET", url, 0); 
                  xmlhttp.send(""); 
                  Response.Write(xmlhttp.responseText); 
                  var xmlhttp = null; 
              </script>
              I tried it but it doesn't work on my page at google pages. Maybe googlepages doesn't support ActiveXObjects?
              I didn't realize googlepages supported asp at all. aren't they running with apache servers? Anyway, I was going to say the syntax looked a little off, but then I saw that you were writing in javascript rather than VBscript so that explains why It looks funky to me. The code in vbscript looks like this:
              [code=asp]<%
              set objHttp = Server.CreateOb ject("Msxml2.Se rverXMLHTTP")
              objHTTP.Open "GET", "http://www.mysite.com" , false
              objHTTP.Send
              Response.Write objHTTP.Respons eText
              %>
              [/code]this sure looks equivalent to me as far as I can tell, so there is probably no problem with your code. IIS included activeX objects from the start because asp is severely limited without them, but I couldn't tell you whether google's servers implement them.

              When you say "it doesn't work" what do you mean? does it give a specific error or freeze up or execute without that line or what?

              Jared

              Comment

              Working...