-
- 275 Posts
Hi,
I built a site which relies heavily on the use of $.ajax from jQuery to dynamically load content from MODX. I implemented this using the templateless document method, described in the MODX documentation. This works quite good, however appears to fail when I switch on friendly URL's.
For example a snippet call like this:
$.ajax({
type: 'GET',
url: 'index.php?id=52',
data: {propertyId: propertyId, month: month, year: year},
success: function(html) {
container.html(html);
spinner.fadeOut(function() {
container.fadeIn('slow');
});
reseed();
}
});
... will no longer work as the arguments are no longer passed into the snippet that is represented by resource with ID 52. Is there a way to solve this?
Thanks.
[ed. note: skndn60 last edited this post 11 years, 5 months ago.]
MODx Revolution / MAMP / OS X
-
- 5,888 Posts
put this javascript-code into your template and let modx generate the url:
$.ajax({
type: 'GET',
url: '[[~52]]',
data: {propertyId: propertyId, month: month, year: year},
success: function(html) {
container.html(html);
spinner.fadeOut(function() {
container.fadeIn('slow');
});
reseed();
}
});
-
- 275 Posts
Quote from: Bruno17 at Nov 11, 2012, 12:35 PMput this javascript-code into your template and let modx generate the url:
$.ajax({
type: 'GET',
url: '[[~52]]',
data: {propertyId: propertyId, month: month, year: year},
success: function(html) {
container.html(html);
spinner.fadeOut(function() {
container.fadeIn('slow');
});
reseed();
}
});
Thanks for the reply.
The javascript is included in a rather large file which gets copied in and therefor is not parsed by the MODX parser, so I'm afraid that will not work.
MODx Revolution / MAMP / OS X
-
- 5,888 Posts
you can define javascript-variables outside of your file.
and use it later in your script with:
-
- 275 Posts
Awesome!! Works great. I've been scratching my head about this one for quite a while.
Thanks for your help.
MODx Revolution / MAMP / OS X