I would like to create an AJAX database call select similar to those on:
http://click.avoka.com/click-examples/ajax/select/ajax-select.htm
or
http://www.w3schools.com/php/php_ajax_database.asp
In the case of the latter example is it possible to replace
getuser.php?q="+str in
xmlhttp.open("GET","getuser.php?q="+str,true);
with a snippet?
If so, an example code for the replace
getuser.php?q="+str test would be appreciated.
Thanks
Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
Create a new Resource with the 'empty' template (0)
Put your snippet-tag into this Resource.
Put your js-code into your template with something like that:
xmlhttp.open("GET","[[~XXX]]?query="+str,true);
Replace XXX with your ajax-resource-id
with jQuery you could do for example:
jQuery.ajax({
type: 'GET',
url: '[[~76]]',
query: str,
success: function(data) {
//do someting with data
}
});
or use any of its shorthand-methods:
http://api.jquery.com/category/ajax/shorthand-methods/
[ed. note: Bruno17 last edited this post 13 years, 8 months ago.]
-
☆ A M B ☆
- 24,524 Posts
AJAX is much easier using JQuery. While I have done raw AJAX (before it came to be called AJAX), it has been some years since I did so.
http://www.w3schools.com/jquery/jquery_ajax_intro.asp
Thanks Bruno and Susan.
Both solutions should do the trick. I came up with Bruno's solution in the middle of the night but didn't get up to try it!
Jim
Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
Anyone can point to more examples of mixing js with modx tags ?
This will skyrocket modx.
you can allways add modx-tags into js-code as long as you do not include the js-code as a js-file.
This can be directly in the template, in chunks or
you can create a static js-resource with modx-tags in it. point it to a js-file and include it with something like that:
<script src="[[~80]]"></script>