Jump to content

Ajax function in included php file not working


puzta

Recommended Posts

Hi,

I'm not sure if this is Ajax related.

I have created a  script where a username is checked with ajax( I use xajax).

 

The ajax function which checks if the user exists is in a seperate file which I include in the actual php file.

The  strange thing is. When I put the function checkuser straight in the script it works fine. When I put the function in a seperate file and use include it's not working anymore.

 

I stripped the script and this is what's left to illustrate the problem I have.

 

<?php
/*** include the xajax bootstrap ***/
require_once( 'includes/config.php');
require_once( 'includes/DBManager.class.php');

$database = new DBManager($host,$username,$pwd,$dbname);
include 'includes/ajax/xajax_core/xajax.inc.php';
/*** a new xajax object ***/
$xajax = new xajax();
/*** register a PHP function with xajax ***/
$rqstButton = $xajax->register(XAJAX_FUNCTION, 'checkUser');
/*** set the request button parameters ***/
$rqstButton->setParameter(0, XAJAX_JS_VALUE, 0);
/*** process the request ***/
$xajax->processRequest();

//include 'functions/func.users.php';
function checkUser()
    {
$content = 'User checked';

        /*** a new response object ***/
        $objResponse = new xajaxResponse();

        /*** assign the innerHTML attribute to the new $content ***/
        $objResponse->assign("my_div","innerHTML", $content);

        /*** return the object response ***/
        return $objResponse;
  }

    /*** the path is relative to the web root mmmk ***/
    $xajax_js = $xajax->getJavascript('includes/ajax');
    /*** process the request ***/
    $xajax->processRequest();
    /*** the path is relative to the web root mmmk ***/
    $xajax_js = $xajax->getJavascript('includes/ajax');
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>

<title>ajax test</title>
<?php echo $xajax_js; ?>
</head>

<body>
<button type="button" onclick="<?php $rqstButton->printScript(); ?>">Check user</button>
<div id="my_div">New text will happen here</div>
</body>

</html>

 

The script as shown here is working but when I put put the function in the included file it's not working anymore.

 

I hope somebody can help me.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.