This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi,
The AJAX framework is workin fine for me when using the data attributes however when I try to use the Javascript API, I receive the following error:
TypeError: $(...).request is not a function
Any help would be greatly appreciated!
Thanks,
Dave
I have the same problem on the rainlab.translate
plugin. I didn't find out what this was caused. It look it comes from the widget. Where are you getting this error?
I'm writing my own component... The data attributes are fine but the request object is not getting loaded and/or is not available from my components htm files...
Don't know why... :(
Make sure you wrap your JavaScript code in {% put scripts %} ... {% endput %}
this will ensure it arrives at the correct location (after jQuery).
@daftspunk... That seems to break my page layout by including the above... Have you got a working code snippet that I can take a look at?
This is an extract of some test code that fails for me...
<button onclick="$(this).request('onRefreshCustomers',{data:{page:100}})">
test
</button>
Last updated
After reading.. https://octobercms.com/docs/markup/tag-scripts
I think I might see the error of my ways.. Its late now so will give this a try tomorrow and let you know how I get on...
Thanks for your help guys...
Moving the {% scripts %} tag in to the head section seems to have fixed my issue...
(I missed your comment before daftspunk... Nice1)
Thanks!
Last updated
Slight spin off problem here...
The code...
function test() {
$(this).request('onRefreshCustomers', {
update: { 'pgCustomer::customers': '#customers_result' },
data: { limit: 30, page:100 }
});
}
I have to specify the component name "pgCustomer" because twig doesn't parse the Javascript files so I cannot use {{ SELF }}::pgCustomer and SELF__ resolves to "test".
How can I get the component name from the included Javascript file?
Cheers!
Last updated
SOLVED!
I put a small script in my default.htm just before I included my {% scripts%} tag to declare some variables, like so....
<script>
var tblLimit = 30;
var tblPages = {{ __SELF__.page_count }};
</script>
{% scripts %}
If there's a better way of doing this I would like to know...
Hope this helps others...
Last updated
1-11 of 11