Topic: Loading $xajax->printJavascript() on a External Javascript

TESTED ON 0.5 RL 2

After reading different post I finally have put them all together to have a working way to load the xajax to a external javascript file.

function getCorrectURI()
{
$split = explode("/",$_SERVER['SCRIPT_NAME']);
$count = count($split) - 1;
return rtrim($split[$count]," ");
}

// xajax
$xajax = new xajax();
$xajax->configure('scriptLoadTimeout', 0); // ADD THIS FOR DEFER FILE
$xajax->configure('requestURI', getCorrectURI()); // ADD THIS FOR DEFER FILE
$xajax->configure('deferScriptGeneration', true); // ADD THIS FOR DEFER FILE
$xajax->setCharEncoding('ISO-8859-1');
// Your XAJAX FUNCTIONS HERE
$xajax->processRequest();

Add the sections that show ' // add this to defer file ';  PLUS YOU NEED TO ADD THE getCorrectURI() Function

Final result will show

<script type='text/javascript' src='index.php?xjxGenerateJavascript=b8d8998efd0128722bdbbb01ee60d74c' charset='UTF-8'></script>

The reason I created the getCorrectURI() is because I use dynamic pages that are in a folder "www.domain.com/folder/" and not "www.domain.com/folder/index.php .  This way it will discover the file name even if the url is different.

Hope this helps.  If you have an idea to make it better let me know and I will update it.

Re: Loading $xajax->printJavascript() on a External Javascript

Our posts crossed - yours is better!

Re: Loading $xajax->printJavascript() on a External Javascript

This is a wonderful opinion. The things mentioned are unanimous and needs to be appreciated by everyone
---------
pharel
Motel Reservations

Re: Loading $xajax->printJavascript() on a External Javascript

I was looking for this. Thank you, Carlitos smile

Re: Loading $xajax->printJavascript() on a External Javascript

Hi,

I think "print($chemin_xajax);" might be your problem.

It will happen every time the page loads and will confuse the xajax code in the browser.

If you put it after $xajax->processrequest() it will only happen on the initial page load.

Hope this helps... smile

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Loading $xajax->printJavascript() on a External Javascript

If we can't fix the problem, do you know another way for the printJavascript() problem and URL Rewriting ?

Re: Loading $xajax->printJavascript() on a External Javascript

Hi everyone,

(I deleted my previous message for security)

I found another way to fix the problem. Because I think this methode doesn't function with Ajax0,5 standart.
If you are using URL REWRITING and you want to fix javascript error you can use this Function.

$path = $_SERVER["DOCUMENT_ROOT"]; 
  
function chemin()  // add this function to know all sub folder of your ROOT
    {
        $a=$_SERVER['REQUEST_URI'];  // this is the magic code If you are using MOD REWRITING
        $b=strrev($a);
        $c=strpos($b,'/');
        $d=substr($b,$c,strlen($b)-$c);
        $e=strrev($d);
        $f=substr_count($e,'/')-1;
        $g='';
        for ($i=0;$i<$f;$i++)
            $g.='../';
        return $g;
    }
$chemin = chemin();  // Call your function

// xajax
require_once("$path/xajax/xajax_core/xajax.inc.php");  
$xajax = new xajax(); //On initialise l'objet xajax
$xajax->configure('javascript URI', $chemin."xajax/");  // include  your path: $chemin 
$xajax->setCharEncoding('ISO-8859-1');

I hope it will Help You!