Hello,
How can I add my php file to modx, not creating a snippet. I need this file to be used in ajax, so it must exist as a file, not in database. But when I add it to snippets folder, the include directives don’t work. For example, in document.parser.class.inc.php it can not learn the type of database(mysql).
How to make a ajax php file, not just snippet? Where to put it, or how to tune modx to work with it properly.
the easiest way to make an ajax-call in modx is
1. create a snippet, which handles your ajax-request.
2. create a new modx-resource with blank template.
3. put your snippet-call to that resource.
4. make your ajax-request to the url of the new created resource.
And how can I pass the parameters to this resource? This is an html file. But I need to pass a parameter to php file. I want to make a list of items which depends on what option is checked in the select tag. So I have to pass a paramter (id of folder-resource) to the php through ajax.
I tryed to use Wayfinder snippet, but I failed passing a variable as a parameter to the wayfinder. For example [[Wayfinder? &startId=id &level=`1`]] Where id is a javascript variable which is defined by the option that user selected in the select tag.
Quote from: mouse22222 at Jan 28, 2011, 08:32 AM
And how can I pass the parameters to this resource? This is an html file. But I need to pass a parameter to php file. I want to make a list of items which depends on what option is checked in the select tag. So I have to pass a paramter (id of folder-resource) to the php through ajax.
I tryed to use Wayfinder snippet, but I failed passing a variable as a parameter to the wayfinder. For example [[Wayfinder? &startId=id &level=`1`]] Where id is a javascript variable which is defined by the option that user selected in the select tag.
don’t send ’id’ as query-parameter to a modx-resource!
’id’ is used for resource-id.
Use ’parent_id’ or something like that.
Install getReqParam - snippet per package-management and use it like that:
[[!Wayfinder? &startId=`[[!getReqParam? &name=`parent_id` &type=`REQUEST`]]` &level=`1`]]
-
☆ A M B ☆
- 24,524 Posts
For an AJAX processor, just pass the parameters as the usual GET or POST in the AJAX request; your snippet code will need to collect and process the GET and POST just as any normal AJAX processor file does. It will also need to echo or return whatever your AJAX request expects; HTML or JSON or whatever.
I have used stock eForm as an AJAX processor exactly as described; on a resource with no template, just the eForm snippet tags exactly as if it were on the displaying page. Instead of the eForm snippet on the page where the form will be, I simply have a container for the AJAX javascript to load eForm’s normal output. So I get the form on first load (clicking a Contact button for example), eForm is again invoked by the AJAX requester on clicking the Submit button, and the form is returned with error messages that can be manipulated in the DOM by the javascript, and any acknowledgment message eForm is configured to generate. And in the meanwhile, eForm does its usual email business (or processing any custom event functions) as normal. It has no way of knowing that it’s not being called by an ordinary page!
Thank you.
But I mean if I create a snippet, how cn I pass it’s address as a parameter to the ajax request. As a first parameter, the request has the address of the php file. for example, mysnippet.php. But if I create a snippet, it is saved in database. How can I refer to it in ajax request?
-
☆ A M B ☆
- 24,524 Posts
Your URL in the AJAX request will be the URL of the page you’ve created to hold the snippet.
http://modxcms.com/forums/index.php/topic,43476.msg259553.html#msg259553
Using JQuery’s load() function and the resource containing the processing snippet given an alias of shareform:
$('#form_window').load('shareform.html', {'name':name, 'email':email, 'fname':fname, 'fmail':fmail, 'message':message, 'formid':'ShareForm'});
This sends the request to shareform.html with the values in the {...} braces, and loads the response into a div with the ID form_window. The eForm snippet in the shareform resource will simply behave as if the form has been submitted as usual. Your custom snippet will do the same.
-
☆ A M B ☆
- 24,524 Posts
Is the AJAX handler resource published? Publicly available? Is it in a subfolder in the Resource Tree and do you have FURL paths enabled?
The first thing to do is to try accessing the URL from your browser window; a temporary "hello, world" text in the content of the resource will let you know if you’ve actually accessed the correct page.
Everything that you asked is yes, except the FURL. What is it?