mrdav30 Posted May 25, 2011 Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/ Share on other sites More sharing options...
gizmola Posted May 25, 2011 Share Posted May 25, 2011 When you say "it doesn't look like" that is not very precise. Have you used firebug's Net panel to see if the connection is occurring? You'd also be able to see the request in your web server access log. Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220274 Share on other sites More sharing options...
mrdav30 Posted May 25, 2011 Author Share Posted May 25, 2011 no i haven't, didn't know i could do that, i've just learned web programming a couple of weeks ago b/c no one else that i work with knew it. i'll try that though and post what i found out, thanks Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220275 Share on other sites More sharing options...
mrdav30 Posted May 25, 2011 Author Share Posted May 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220298 Share on other sites More sharing options...
gizmola Posted May 25, 2011 Share Posted May 25, 2011 If firebug is showing you the response data that the script should return, then I would look into the javascript code that works with the value. Firebug also has a javascript debugger. It's an amazing tool Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220305 Share on other sites More sharing options...
mrdav30 Posted May 25, 2011 Author Share Posted May 25, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220309 Share on other sites More sharing options...
gizmola Posted May 26, 2011 Share Posted May 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220313 Share on other sites More sharing options...
mrdav30 Posted May 26, 2011 Author Share Posted May 26, 2011 thanks for all your help guys!, definetly still learning a lot Quote Link to comment https://forums.phpfreaks.com/topic/237473-ajax-not-pulling-up-php-for-query/#findComment-1220888 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.