Link to home
Start Free TrialLog in
Avatar of ALASKASTREETMASTER
ALASKASTREETMASTERFlag for United States of America

asked on

xajax query

I have created 2 php pages.  The first using php will perform the query and echo the value from the database. This works fine.

The second page, when calling from a javascript using xajax has no results. No errors other than 'undefined'.

Is it possible the xajax is not working?  When I look at the source on the page and it looks like it is finding what it needs.  Is there a way to tell if xajax is working?

Help!

 
////  This php page will get the taxid  ///
http://66.29.204.170/Products/WebImages/test2.php
<?php
 
require_once("xajax/xajax_core/xajaxAIO.inc.php");
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
$xajax->registerFunction("getll");
$xajax->processRequest();
 
 
$lonquery =  '-149.8375..-149.8373';
$latquery =  	'61.12851..61.12871';
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$lonquery);
$findCommand->addFindCriterion('LATNUM',$latquery);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
	$taxid = $record->getField('TAXID_11');
	$lat = $record->getField('LATNUM');
	$lon =  $record->getField('LONNUM'); 	  	    	
	$row++;
 
}
		
echo $taxid;
?>
 
//  Page Two  ////  This page returns no data.
http://66.29.204.170/Products/WebImages/axajaxtest.php  
<?php
 
  require_once("xajax/xajax_core/xajaxAIO.inc.php");
 
  $xajax = new xajax();
  $xajax->configure('javascript URI','xajax/');
 
  $xajax->registerFunction("getll");
 
  $xajax->processRequest();
 
 
function getll($arg){
  $lonquery =  '-149.8375..-149.8373';
  $latquery =  	'61.12851..61.12871';
 		  	   	 require_once("FileMaker.php");
 		  	   	 $fm = new FileMaker('Cama');
 		  	   	 $findCommand =& $fm->newFindCommand('ASMLATLON');
 		  	      $findCommand->addFindCriterion('LONNUM',$lonquery);
 		  	      $findCommand->addFindCriterion('LATNUM',$latquery);
 		  	   	 $result = $findCommand->execute();
 		  	   	 $records = $result->getRecords();
 
 		  	   	$row = 0;
 
 		  	   	foreach ($records as $record) {
 
 		  	   	     $taxid = $record->getField('TAXID_11');
 		  	   	     $lat = $record->getField('LATNUM');
 		  	   	     $lon =  $record->getField('LONNUM');
 		  	  	    	$row++;
 		}
 
 $newContent = "Value of arg:" . $arg;
 $objResponse = new xajaxResponse();
 $objResponse->addAssign("SomeElementId","innerHTML", $newContent);
 $objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
 return $objResponse;
 
}
 
 
 
  ?>
 
  <html><head><title>Xajax test</title>
  <?php $xajax->printJavascript(); ?>
  <script type="text/javascript">
  x=0;
  var taxid;
   xajax_getll()
    //alert(taxid);
  </script>
 
  </head><body>
 
  <div id="SomeElementId"></div>
 <button onclick="javascript:xajax_getll();alert(taxid)">test</button>
 
   </body>
  </html>

Open in new window

Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Change line 72:

  $objResponse->addAssign("SomeElementId","innerHTML", $newContent);

...into:

  $objResponse->Assign("SomeElementId","innerHTML", $newContent);

Line 94:

<button onclick="javascript:xajax_getll();alert(taxid)">test</button>

Change it to this:

<button onclick="xajax_getll();">test</button>

When this is called the first time, taxid will be undefined, because ajax is asynchron. It takes some time for the request to return and set taxid to some value. So you can not alert(taxid) here. Do it with a separate button.
Don't call xajax_getll() in line 87.
Avatar of ALASKASTREETMASTER

ASKER

i made the changes but still get 'undefined'.
If I don't declare the variable:
var taxid;
the page gets an error sayig taxid undefined.
If i declare it, then the alert says undefined.

I get no other errors.

is there some simple way echo $taxid on a page to see if it is working?
I have tried the echo $taxid command but it does nothing.

  <?php
 
  require_once("xajax/xajax_core/xajax.inc.php");
 
  $xajax = new xajax();
  $xajax->configure('javascript URI','xajax/');
 
  $xajax->registerFunction("getll");
 
  $xajax->processRequest();
 
 
function getll($arg){
  $lonquery =  '-149.8375..-149.8373';
  $latquery =  	'61.12851..61.12871';
 		  	   	 require_once("FileMaker.php");
 		  	   	 $fm = new FileMaker('Cama');
 		  	   	 $findCommand =& $fm->newFindCommand('ASMLATLON');
 		  	      $findCommand->addFindCriterion('LONNUM',$lonquery);
 		  	      $findCommand->addFindCriterion('LATNUM',$latquery);
 		  	   	 $result = $findCommand->execute();
 		  	   	 $records = $result->getRecords();
 
 		  	   	$row = 0;
 
 		  	   	foreach ($records as $record) {
 
 		  	   	     $taxid = $record->getField('TAXID_11');
 		  	   	     $lat = $record->getField('LATNUM');
 		  	   	     $lon =  $record->getField('LONNUM');
 		  	  	    	$row++;
 		}
 
$newContent = "Value of arg:" . $arg;
$objResponse = new xajaxResponse();
$objResponse->Assign("SomeElementId","innerHTML", $newContent);
 $objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
 return $objResponse;
 
}
 
 
 
  ?>
 
  <html><head><title>Xajax test</title>
  <?php $xajax->printJavascript(); ?>
  <script type="text/javascript">
  x=0;
  var taxid ;
  </script>
 
  </head><body>
 
  <div id="SomeElementId"></div>
 <button onclick="xajax_getll();">test</button>
 <button onclick="javascript:alert(taxid)">alert</button>
 
   </body>
  </html>

Open in new window

Do you have two spaces before your opening php start tag: "  <?php". If so, that is the problem. I can't find anything else wrong.

Do you get the "Value of arg:" message?
there was 2 spaces.  but it did not make any difference.  Been here many times beofre, work at it all day and still where you were when you started. should have been a dentist.

What do you suggest?  Are there some tests I could do to see where it is failing?
thanks appreciate your help.




<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
 
function getll($arg){
$lonquery =  '-149.8375..-149.8373';
$latquery =  '61.12851..61.12871';
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$lonquery);
$findCommand->addFindCriterion('LATNUM',$latquery);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
 
$newContent = "Value of arg:" . $arg;
$objResponse = new xajaxResponse();
$objResponse->Assign("SomeElementId","innerHTML", $newContent);
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}
 
 
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
</script>
 
</head><body>
 
<div id="SomeElementId"></div>
<button onclick="xajax_getll();">test</button>
<button onclick="javascript:alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

no value of arg message, no messages or errors at all.
That script works for me. I don't have your Filemaker db, so I simplified the function. Nothing else is changed:
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
function getll($arg){
$row = 111;
$taxid = 222;
$newContent = "Value of arg:" . $arg;
$objResponse = new xajaxResponse();
$objResponse->Assign("SomeElementId","innerHTML", $newContent);
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse; 
}
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
</script>
 
</head><body>
 
<div id="SomeElementId"></div>
<button onclick="xajax_getll();">test</button>
<button onclick="javascript:alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

I still get the undefined message.  Something must be wrong with the xajax install.
i first installed the xajax 5.0 compiled, then tried the xajax 5.0 standard.  Do I have the right version?
I have 0.5 standard, but I think it is the same version, just different compression level.

Check web server error log.

Do "View source" in the browser, check that the xajax javascript is there.
Previously you had this:

require_once("xajax/xajax_core/xajaxAIO.inc.php");

I removed "AIO", the file is just named xajax.inc.php in the standard install. Is xajaxAIO a copy, or did you rename the file?
that is the name of the file in the compressed version.  The standard and full version both have the  xajax.inc.php file. I just switched to the full version. did not make a difference.

the code below is what comes up when I view source on the code i got from you


<html><head><title>Xajax test</title>
 
<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = "http://www.streetmaster-ak.com/products/webimages/test7.php";
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = "xajax 0.5";
xajax.config.legacy = false;
xajax.config.defaultMode = "asynchronous";
xajax.config.defaultMethod = "POST";
/* ]]> */
</script>
<script type="text/javascript" src="xajax/xajax_js/xajax_core.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
window.setTimeout(
 function() {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert("Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?\nURL: xajax/xajax_js/xajax_core.js");
  }
 }, 2000);
/* ]]> */
</script>
 
<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
xajax_getll = function() { return xajax.request( { xjxfun: 'getll' }, { parameters: arguments } ); };
/* ]]> */
</script>
<script type="text/javascript">
x=0;
var taxid ;
</script>
 
</head><body>
 
<div id="SomeElementId"></div>
<button onclick="xajax_getll();">test</button>
<button onclick="javascript:alert(taxid)">alert</button>
 
</body>
</html> 

Open in new window

Im not too up on the viewing log files on the server (Windows 2003) where would I look?
Running firefox, I get this message when I visit your page:

<b>Warning</b>:  Missing argument 1 for getll() in <b>M:\web\users\testcom\html\Products\WebImages\test7.php</b> on line <b>12</b><br />

I don't get this message on my server. Anyhow, the getll() function is defined with one parameter, and you call it without any argument. Easy to fix, either remove the $arg parameter from the function definition or use it when you call the function.
Which web server? IIS or apache? Version?
so also remove lines 4 and 6below since $arg is no longer beig used?
function getll($arg){
$row = 111;
$taxid = 222;
$newContent = "Value of arg:" . $arg;
$objResponse = new xajaxResponse();
$objResponse->Assign("SomeElementId","innerHTML", $newContent);
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
}

I appreciate your patience.  I am picking it up though.  thanks!
IIS 6.0
ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, got it going. Rebooted the server. go figure.