Solved

xajax query

Posted on 2009-04-07
20
945 Views
Last Modified: 2013-12-13
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
Comment
Question by:ALASKASTREETMASTER
  • 11
  • 9
20 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24091883
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24091893
Don't call xajax_getll() in line 87.
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24092034
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24092279
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24092692
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24092740
no value of arg message, no messages or errors at all.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24092803
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24092879
I still get the undefined message.  Something must be wrong with the xajax install.
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24092890
i first installed the xajax 5.0 compiled, then tried the xajax 5.0 standard.  Do I have the right version?
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24092964
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24092983
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24093014
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24093052
Im not too up on the viewing log files on the server (Windows 2003) where would I look?
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24093071
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24093084
Which web server? IIS or apache? Version?
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24093111
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24093113
IIS
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24093119
IIS 6.0
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24093160
0
 

Author Closing Comment

by:ALASKASTREETMASTER
ID: 31567728
thanks, got it going. Rebooted the server. go figure.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question