Questions tagged [ajax]
The ajax tag has no usage guidance.
175
questions
17
votes
3
answers
7k
views
How do i setup ajax paging for entries
Im looking for a good way to setup paging for new items with a simple "load more" button at the bottom.
I know i'd use something like
{% if craft.request.isAjax %}
on the listing template to not ...
10
votes
5
answers
17k
views
Updating a user on the front end with Vue.js and Axios
I currently have a working profile update form using purely craft but I would like to now enhance that using Vue and Axios to update via Ajax. I may well submit a couple of questions rather than put ...
9
votes
2
answers
8k
views
How can I use CSRF protection with AJAX routes?
I have CSRF enabled on my install. I have a bunch of frontend forms so CSRF is pretty important for me. However, when I use AJAX to post to a controller action I get the following error.
<div id="...
7
votes
2
answers
4k
views
Do I need a plugin to load entries via AJAX?
I want to load some entries via AJAX. I have a page that normally shows all entries of a specific type with user-selectable filters. I want to load filtered entries via AJAX.
Do I need to create a ...
6
votes
1
answer
2k
views
Searching a specific section by four different types of parameters?
I'll do my best to explain this.
I have a Portfolio of companies, which I have as a structure, that I need to be able to filter/search through by using up to four different parameters.
Keyword - a ...
6
votes
3
answers
1k
views
Refreshing meta data when using AJAX page transitions
I have created AJAX page transitions based on:
https://designbycosmic.com/journal/craft-cms-ajax-page-transitions-with-history-pushstate
It's all working nicely, the main content of the site (...
6
votes
2
answers
2k
views
Craft CMS and JS/MVVM frameworks
Does anyone have an experience in using Craft in conjunction with a front-end JS MVC/MVVM framework such as Backbone, Ember or Angular?
We have a project coming up where there may be a lot of JS ...
6
votes
1
answer
2k
views
Ajax front-end user registration form - not returning JSON
I have a user registration form on the front-end of a site that is working well as a standard form, but when I try to use ajax submission, I'm getting an HTML response rather than JSON.
Here's the ...
6
votes
1
answer
940
views
Delete items from frontend with ajax
I'm trying to delete items through the frontend with ajax. It's working now but want to be sure if this is a safe method:
$(".delete-file").click(function(){
var data = {
entryId: $(this)....
5
votes
4
answers
1k
views
How can I set the HTTP status code?
I'm trying to set a 404 HTTP status response code for an ajax controller action in a plugin.
Yii has a response object where the code can be set, but I can't find a way to access it from craft.
5
votes
2
answers
7k
views
How to load entries via ajax when a filter is clicked?
I have a page that lists all entries from the section 'work'. I would like the user to be able to filter these entries by category but via ajax so I don't have to go to a new page.
{% set entries = ...
5
votes
1
answer
3k
views
Update Commerce Cart using Ajax
Is there a way to update the cart using ajax?
I've tried something like:
$('span.quick-cart-add>p>a').click(function(e){
e.preventDefault();
var data = {};
...
5
votes
2
answers
460
views
Possible to change locale in PHP?
I've got a plugin which is defaulting to English during AJAX calls, but I need it to stick to whatever the current language is. I can send the current locale through via AJAX data, but I'm not sure ...
5
votes
1
answer
1k
views
Getting server-side feedback when submitting forms with jQuery Form plugin
I've got a few simple front-end forms that users can use to update their profiles. I'm using the combo of the jQuery Validate and Form plugins to handle validation and submission.
I can successfully ...
4
votes
1
answer
3k
views
Basic ajax - how to?
I am new to Craft. I have done some ajax in the distant past. I have searched this forum and see lots of issues with ajax but it seems that there are a lot of different approaches. Craft docs have ...
4
votes
1
answer
3k
views
How to load entry-objects with Ajax
I should begin to say that I have no idea really how exactly ajax works. Although I've used it a couple of times with pre-made WordPress plugins. I saw some examples of ajax entry-loading here on ...
4
votes
2
answers
489
views
Is there a way to divide an entry's data into multiple subviews with unique URLs?
I have a one-level structure where I am storing a client's projects, with the ability to reorder them by dragging the entries in the structure.
Each project has been designed to have multiple ...
4
votes
2
answers
1k
views
Twig Filter in Plugin/PHP?
Is it possible to access twig filters in a plugin? I want to be able to preview how text will look in a textarea using Markdown for a discussion board, it'd be awesome to use ajax to send the content ...
4
votes
2
answers
2k
views
Front end login form with ajax
Im trying to get a front end login form to work over ajax and running into issues, it seems to always pass back success and not sure how to actual make sure the cookie gets created and the user is ...
4
votes
3
answers
883
views
P&T Contact Form plugin: How to display error messages in other languages via Ajax
The validations error message get displayed in main language instead of being translated, you can try here (contact form at bottom):
http://lequartiergeneral.be/en/
The form is being displayed and ...
4
votes
1
answer
1k
views
Update cart lineItems through ajax
How do I update the lineItems after I submit the form through ajax? right now it adds the item, but it doesn't show up in the cart, it only shows up when I reload the page.
I am adding an item to ...
4
votes
1
answer
4k
views
Call plugin controller from frontend with ajax
I want to send an automatic back office email when user click on a button (to request support) on frontend. Then I just display a confirmation message (we ll get back to you shortly).
So I made a ...
3
votes
2
answers
5k
views
What is the best way to append CSRF token without using a form?
I have built a plugin that simply makes requests to a 3rd party API. I am calling my plugin action via ajax.
I don't have a form on this page currently. Here is what I am using, but I am getting the ...
3
votes
3
answers
1k
views
Filter entries with AJAX
How would I sort blog entries displayed using AJAX?
What I want to achieve is initially show all posts from a channel (All) but then let my users sort through these posts with a sub navigation using ...
3
votes
3
answers
7k
views
Is it possible to update a Twig variable based on user interaction without page refresh?
I'm currently trying to use the excellent "Charge" plugin to set up a simple Stripe checkout form for charity donations. The basic example provided in the docs works nicely.
<form method="post">...
3
votes
2
answers
761
views
Loading related entries by category using a select menu
I have a list of people (entries) who are related to Categories.
I would like to create select menu which will change (filter) the people (entries) shown on the page depending on which category (...
3
votes
1
answer
1k
views
Search Contact Person Plugin via Ajax
I'm new to Craft and I'm trying to achieve the following with a Craft Plugin
A user visits my site and can input a zip code to receive the corresponding contact person's name, phonenumber and image. ...
3
votes
1
answer
1k
views
How do I access AJAX data within a controller method?
I have a JavaScript file which sends an array of data to a controller:
Craft.postActionRequest('wineNotes/wineSpreadSheet/saveWines', data, ...)
The structure of the data variable is as follows:
...
3
votes
1
answer
1k
views
Access data when posting to controller from front-end
I'm writing a plugin to notify authors when a Disqus comment is posted. There is a Disqus JS callback you can use to hook into this, so I'm doing the following on the front-end:
this.callbacks....
3
votes
1
answer
421
views
Load correct language Ajax
I'm having a problem with my ajax-loading when I'm on the english version of my page (My main language is Norwegian). I have a file named loadmore.html that I'm loading in on index.html when pressing ...
3
votes
0
answers
140
views
How can my plugin use Craft's native dragdrop support
I am using a generic Garnish modal from Craft like so:
$container = $('.upload-modal');
$modal = new Garnish.Modal($container, {
autoShow: false
});
I would like to have craft's native drag&...
2
votes
3
answers
655
views
Triggering JavaScript from back-end event
I'm building a plugin and want to trigger some JavaScript on an event being fired (eg an entry being saved). What is the best way to achieve this? Coming up short looking through the documentation and ...
2
votes
2
answers
4k
views
Craft 3 - ajax request to plugin
This is a pretty simple test before I implement some larger functionality. Eventually this will be just a glorified upload form via ajax.
Part 1 - Ajax post
$.ajax({
type: 'POST',
...
2
votes
3
answers
941
views
How can I use Ajax function in Craft CMS?
I want to do an autocomplete search engine on my website. But I don't know how to use Ajax in Craft CMS. How can I set an Ajax function in Craft CMS templating? The search engine must have dynamic ...
2
votes
2
answers
962
views
How could I include another template on a click with ajax?
I am a newbie with ajax and I have to display a template only when clicking on a button. This template is weighing and it will be on all pages, so I want to use ajax.
Someone can help me?
2
votes
2
answers
1k
views
ElementAPI - Can I use javascript/ajax to load json
Probably a dumb question, but since i wasn't sure while reading on github, i'll ask here.
I am wondering if I can reach the JSON I created with an URL or is it only for use in PHP?
I would like to ...
2
votes
2
answers
3k
views
How can I call a controller method from the front-end using ajax
I would like to call an action method from within my plugin via ajax but I am always getting a 404 response.
I have a controller method that matches the ajax url:
jquery
$.ajax({
'type': 'post'...
2
votes
1
answer
1k
views
AJAX page transitions with history.pushState
I'm a new craft user (previous EE user). trying to follow Zack Spear's directions (https://designbycosmic.com/journal/craft-cms-ajax-page-transitions-with-history-pushstate) for how to setup Ajax page ...
2
votes
2
answers
1k
views
Navigation with AJAX
I haven't used AJAX a lot, but what I want to do is the following:
I have a top navigation that outputs entries from a structure which link to various singles that display my data.
I want my ...
2
votes
2
answers
2k
views
How do I get the current user’s info over Ajax?
I created an Ajax-based login form based on this gist: https://gist.github.com/keithmancuso/29e8446ec5fa66fb2b01.
After the user has logged in, how can I get some info about them over Ajax?
2
votes
1
answer
1k
views
How do you correctly handle errors using PT Contact Form when submitting via AJAX?
I'm trying out AJAX submission for the PT Contact Form for the first time. I've managed to get errors appearing on the frontend, but I don't feel like I'm doing it the right way. It also doens't ...
2
votes
1
answer
2k
views
CSRF in “Headless” Applications
There are a number of answers here about how to send CSRF tokens along with AJAX requests, but I think my question is a little different. Please excuse the abstractness here:
In a headless ...
2
votes
1
answer
954
views
Ajax Post to guestEntries/saveEntries from another domain
I have a separate Craft install that I am using to communicate to a few different sites. I have a front-end form on another one of these sites (a React.js app) that is looking to post back to this ...
2
votes
1
answer
1k
views
How to check for new entries periodically from the front-end?
I would like to check periodically (every 5 seconds for example) whether there are new entries in a channel. If yes, I would like to present a refresh button on the website (with the number of the new ...
2
votes
1
answer
2k
views
Sort / Order Entries on select or button click
I have a page on my website were I display alot of entries. Now I want those entries to be sorted by Date, Title etc. I know how to change that hard coded but I want to make it dynamic with a <...
2
votes
1
answer
517
views
Using ajax with routes is it right?
So doing some entries loading via ajax from this question which I expanded on.
https://craftcms.stackexchange.com/a/9868/3579
I'm curious about setting up a route for the actual ajax file since it ...
2
votes
1
answer
1k
views
Dynamically populating select input fields using jquery $.load and twig template
EDIT: the below code now works!
I have two select inputs, the choice of 1 should populate the second. I have an external twig file (data.twig) (MAKE SURE TO PUT THIS IN YOUR TEMPLATES FOLDER) that ...
2
votes
1
answer
5k
views
Axios post function got 400 bad request
I created a Vue component. And in this component, I use axios to send post request when it's mounted, CSRF token also included, but still got 400 status. Anyone know why?
2
votes
1
answer
529
views
AJAX Front-end User Registration Form not displaying macro errorList
I have a user registration form on my Front-end which is submitted with Ajax which works fine.
The only problem is that if I have any errors, like an already in use username they wont be displayed. ...
2
votes
2
answers
2k
views
How to do an ajax submission to Craft Contact Form with attachments using FormData?
JS
.on('submit', '#application-form', function(e) {
e.preventDefault();
var form = $(this),
formData = new FormData(form[0]),
msgBox = form.find('.msg-box'),
...