Solved

xajax query

Posted on 2009-04-07
20
939 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
Comment Utility
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
Comment Utility
Don't call xajax_getll() in line 87.
0
 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
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
 
LVL 39

Expert Comment

by:Roger Baklund
Comment Utility
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
Comment Utility
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
Comment Utility
no value of arg message, no messages or errors at all.
0
 
LVL 39

Expert Comment

by:Roger Baklund
Comment Utility
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
Comment Utility
I still get the undefined message.  Something must be wrong with the xajax install.
0
 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

Expert Comment

by:Roger Baklund
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Which web server? IIS or apache? Version?
0
 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
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
Comment Utility
IIS
0
 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
IIS 6.0
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
Comment Utility
0
 

Author Closing Comment

by:ALASKASTREETMASTER
Comment Utility
thanks, got it going. Rebooted the server. go figure.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now