Developer forum

Forum » Development » Best practice apporach catching ajax calls

Best practice apporach catching ajax calls

Jan Sangill
Reply

Hi,

What is the most optimal way of catching an ajax call from frontend.
1) Create a cshtml file and add it in /Admin/public? Do your logic in this
2) Create a subscriber , like Standard.Application.AfterBeginRequest and catch the URL and do your logic
3) Something else?

 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

We typically do 3) - something else ;-) Here's what we do:

1. We've created a super simple module called the TenmplateRenderer. All it does is take a template as part of its config screen that it renders when it's executed.

2. We then use that module with CSHTML templates to render specific (AJAX) functionality

3. We set up pages in the backend (in a sub folder structure like System/Ajax for example) for specific purposes. These pages can be set up to return JSON (or whatever you want) and execute the requested template using whatever server side logic is needed. For module specific scenarios (like a mini cart that is loaded on demand), we use the module itself and its templates, bypassing the custom TemplateRenderer module.

Does this help? Let me know if you need more examples on any of these steps.

Cheers,

Imar

 

 
Nicolai Pedersen
Reply

You might also find some inspiration here:

http://doc.dynamicweb.com/documentation-9/how-tos/general/implementing-typeahead-search

 
Jan Sangill
Reply

Thank you both for the replies.
Its given me someinspiration for non custom solutions atleast.

 

You must be logged in to post in the forum