So....
one document outputs some ajax request....let’s say ajax_output
the document which handles the ajax calls si ...let’s say ajax_processing
in the ajax_processing document, there is only a snippet, [!ajax_functions!]...
in the [!ajax_functions!] snippet there is an include_once function:
[tt]include_once $snipPath."ajax_functions.inc.php";[/tt]
Everything is working.... but when I tried to redirect with $modx->makeURL and $modx->sendRedirect functions, from the PHP file, I get the following error message (in the eclipse editor, because the browser doesn’t say anything about it, it just stays in that state without getting some redirected page):
Fatal error: Call to a member function makeURL() on a non-object in F:\www\modx\assets\snippets\ajax_functions.inc.php on line 3
In the [!ajax_functions!] snippet, $modx object is recognized because I got a redirection in there too, and it is working fine...
I tried to put global $modx; in the first line of the php file..... still the error is appearing....
the structure, as I see it (wrong maybe) is exactly as weblogin or websignup snippet which has some files in the assets/snippets/weblogin directory
what is the problem?...because I’m out of ideas..... it is from the ajax?....
btw: ajax_processing document has no template (just the [*content*] template variable)...but everything is working nice, except recognition of the $modx object in the PHP file....
It seems that $modx object is recognized and something else is the problem why the redirection is not happening....
and the pb maybe that even if the redirection is happening, any final output is returned to the ajax call... and that’s why the browser stays... because it receives the output of the page I tried to redirect to....
I guess that means that I have to change the header or something.... it it beyond my reach....
yep...that’s it....
I called the alert function in javascript with the ajax response and as I suspected, it is the whole page in there....
so anyone who wants to redirect between the ajax call and ajax response, DONT DO IT:)...
it seems that I have to set some session variables instead, to announce the error, instead of redirection...
-
☆ A M B ☆
- 24,524 Posts
When your AJAX request calls another file, that file is being called externally and is not part of the MODx parsing process and has no access to the $modx object. Your external AJAX processors need to include the manager/includes/config.inc.php file and the manager/includes/document.parser.class.inc.php file, then make a new $modx object for itself. There is a class that will simplify the process available
here.