This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
williamson.t.p23282
I have a simple ajax form on a blog post and I want to access the blog post data from within my ajax functions. Does anyone know how?
pratyushpundir6424
You can just use the twig variables inside of your javascript. Something like so:
Assuming you have the blogPost loaded up thru twig as blogPost
:
In your form you could just do:
<form>
<button type="submit" data-request="yourEventHandler" data-request-data="postId: '{{ blogPost.id }}'">Make AJAX request</button>
</form>
This will send thru your blogPost.id as post data to your AJAX handler. Key name in post data would be 'postId' in this example.
1-3 of 3