• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 973
  • Last Modified:

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

0
ALASKASTREETMASTER
Asked:
ALASKASTREETMASTER
  • 11
  • 9
1 Solution
 
Roger BaklundCommented:
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.
0
 
Roger BaklundCommented:
Don't call xajax_getll() in line 87.
0
 
ALASKASTREETMASTERAuthor Commented:
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

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Roger BaklundCommented:
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?
0
 
ALASKASTREETMASTERAuthor Commented:
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

0
 
ALASKASTREETMASTERAuthor Commented:
no value of arg message, no messages or errors at all.
0
 
Roger BaklundCommented:
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

0
 
ALASKASTREETMASTERAuthor Commented:
I still get the undefined message.  Something must be wrong with the xajax install.
0
 
ALASKASTREETMASTERAuthor Commented:
i first installed the xajax 5.0 compiled, then tried the xajax 5.0 standard.  Do I have the right version?
0
 
Roger BaklundCommented:
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.
0
 
Roger BaklundCommented:
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?
0
 
ALASKASTREETMASTERAuthor Commented:
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

0
 
ALASKASTREETMASTERAuthor Commented:
Im not too up on the viewing log files on the server (Windows 2003) where would I look?
0
 
Roger BaklundCommented:
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.
0
 
Roger BaklundCommented:
Which web server? IIS or apache? Version?
0
 
ALASKASTREETMASTERAuthor Commented:
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!
0
 
ALASKASTREETMASTERAuthor Commented:
IIS
0
 
ALASKASTREETMASTERAuthor Commented:
IIS 6.0
0
 
Roger BaklundCommented:
0
 
ALASKASTREETMASTERAuthor Commented:
thanks, got it going. Rebooted the server. go figure.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now