Jump to content

ajax not pulling up php for query


mrdav30

Recommended Posts

I've been working on this program for a little bit now, and now i'm stuck.  It doesn't seem like my ajax is calling on my php file to do the query.  Everything looks sound to me, I was hoping that maybe someone would see something that i might have messed up.

 

My html code:

<html>
<head>
    <title>helloscan</title>
          <meta http-equiv="refresh" content="18">        
          <meta http-equiv="scanner" content="javascript:doScan('%s');"/>
          <meta http-equiv="scanner" content="start"/>
          <META HTTP-Equiv="scanner" Content="enabled" />
          <META HTTP-Equiv="scanner" Content="autoenter:enabled" />
          <META HTTP-Equiv="keycapture" content="acceleratekey:all" />
          <META HTTP-Equiv="keycapture" content="keyvalue:0x0D; keyevent:'javascript:get_plunum()'" />        
          <meta http-equiv="quitbutton" content="visibility: visible;"/>       
    <script language="javascript" type="text/javascript">
    //produces variable for ae_xrefnum
      function doScan(data){
          var divEl = ("%s");
      }
      //on refresh, allows scanner to come back up
      function enablescanner(enable){
         Generic.InvokeMetaFunction('scanner', 'start');
         Generic.InvokeMetaFunction('scanner', 'enabled');
         Generic.InvokeMetaFunction('scanner', 'autoenter:enabled');  
      </script>
      <script language="javascript" type="text/javascript">
      //called from meta tag after autoenter attached to scan, checks to make sure ajax active, then send out query for ae_xrefnum
      function get_plunum(){
         xmlhttp=ajaxfunction();
         if (xmlhttp==null) {
            alert ("no ajax support");
            return;
        }
         //function that sets var for query
         var ae_xrefnum = document.getelementbyid('ae_xrefnum').value;
         var querystring = "?ae_xrefnum=" + xrefnum;
         xmlhttp.onreadystatechange = function () {
         //receives data from server, and puts repsonse in ae_plunum field
            if (xmlhttp.readystate == 4 || xmlhttp.readystate=="complete"){
                   document.myform.ae_plunum.value = xmlHttp.responseText;
         }
           }
      //sends to php to query
      xmlhttp.open("GET", "helloscan2.php"+querystring, true);
      xmlhttp.send(null);
      }
      function ajaxfunction(){
        var xmlhttp=null;
        try {// code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp=new XMLHttpRequest();
        }
        catch (err) {// code for IE6, IE5
           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlhttp;
      }            
     </script>
</head>
<body  onload="enablescanner(true)">
    <h3 align="center"><center><img src="ac moore" /></center>Please scan a barcode...</h3>
    <form  name="myform">
    ItemBarcode:
    <input type="text" id="ae_xrefnum" name="ae_xrefnum" itembarcode="divE1" /> 
    plunum:
    <input type="text" id="ae_plunum" name"ae_plunum" oninput="get_price()"/>
    <input type="submit" id="submitbtn" value="submit me" onsubmit="get_plunum" />
    </form>
    <script language=javascript>
    //focuses on ae_xrefnum when refresh occurs or page loads
        {
          document.myform.ae_xrefnum.focus();
        }
    </script>
</body>
</html>

 

and my php file:

<?php
//================================================================

  // Configure connection parameters
  $connect_string="DRIVER={Sybase SQL Anywhere 5.0}; SERVER=ACMSQL036A; DATABASE=BACKOFF";
  $dbuser="DBA"
  $dbpswd="SQL"

//================================================================

  // Connect to DB
  $conn = odbc_connect($connect_string, $dbuser, $dbpswd);


  // Query
  $xrefnum = $_GET['ae_xrefnum'];
  $qry = "SELECT xrefnum, plunum FROM DBA.PLU_Cross_Ref where xrefnum = '$xrefnum'";

  // Get Result
  $result = odbc_exec($conn,$qry);
   if (!$conn)
  {exit("Connection Failed: " . $conn);
  }

  // Get Data From Result
  $row=odbc_fetch_array($result);
  
  // Show data
  print($row[plunum]);
  }

  // Free Result
  odbc_free_result($result);

  // Close Connection
  odbc_close($conn);

  

//================================================================
?>

 

I'm tired of googling and looking through forums, no matter what i try it won't query xrefnum and from that populate the ae_plunum field with plunum from my database.  Any help would be very appreciated.

Link to comment
Share on other sites

GET helloscan.html?ae_xrefnum=715717718895

 

304 Not Modified

 

97.0.40.244

 

3 KB

 

 

16ms

ParamsHeadersResponseCacheHTML

Response Headersview source

Date Wed, 25 May 2011 23:22:13 GMT

Server Apache/2.2.19 (Win32) PHP/5.3.6

Last-Modified Wed, 25 May 2011 23:15:51 GMT

Etag "100000000728f-c05-4a421e2be1a9d"

Accept-Ranges bytes

Content-Length 3077

Content-Type text/html

Request Headersview source

Host 97.0.40.244

User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language en-us,en;q=0.5

Accept-Encoding gzip, deflate

Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive 115

Connection keep-alive

If-Modified-Since Wed, 25 May 2011 23:15:51 GMT

If-None-Match "100000000728f-c05-4a421e2be1a9d"

Cache-Control max-age=0

 

so does this mean that it connects? i think from looking through the firebug netpanel, that my response is coming back as my whole html page, not my query

Link to comment
Share on other sites

This should put my query into the ae_plunum field right? I think this might be my problem if not

var ae_xrefnum = document.getelementbyid('ae_xrefnum').value;
         var querystring = "?ae_xrefnum=" + xrefnum;
         xmlhttp.onreadystatechange = function () {
         //receives data from server, and puts repsonse in ae_plunum field
            if (xmlhttp.readystate == 4 || xmlhttp.readystate=="complete"){
                   document.myform.ae_plunum.value = xmlHttp.responseText;

Link to comment
Share on other sites

Yes but that's why you should use the firebug net panel.  You will see a line when the ajax call goes, and you will see what the url is and what the response data is.  If there is a problem with the get param, you will see it there.  You can also try the good old alert in there for the xmlHttp.responeText. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.