Download the PHP package madj2k/t3-ajax-api without Composer

On this page you can find all versions of the php package madj2k/t3-ajax-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package t3-ajax-api

ajax_api

What does it do?

It adds AJAX-functionality to your extensions in an easy and convenient way. There is no need to take care of AJAX request by yourself. Just code your extension and templates as usually – ajax_api will take care of the rest

Setup

Usage

Basics

First you will have to extend your ActionContoller from the AjaxControllerAbstract. This way the AJAX- functionality is added to your extension.

Now that the basic functionality is available we can use it. This is best explained using an example.

Example

Let's pretend you have an extension which:

The Fluid-code may look like this:

So we probably want to archive the following behavior:

In order to archive this behavior we have to use the AjaxWrapper-ViewHelper. This ViewHelper marks the sections in your HTML that are to be used for Ajax. With it you can also define which action should take place. The AjaxWrapper-ViewHelper expects the following params:

First, lets take a look at the changed code before we try to explain why we did it this way:

This will be code rendered to the frontend like this:

As you can see the AjaxWrapper-ViewHelpers will add some attributes to their first child elements. Note that these attributes will only be added to a defined set of valid HTML-tags (e.g. DIVs and FORMs). What did we do? We told the extension to:

What is still missing is an information about when these actions are to be executed. This is done by setting some params to the links and forms with the additionalParams-attribute. You can combine the following params with custom params for your extension.

Let's take a look on the params and what they do:

Let's integrate that into our example:

This way the FORM with the param idl=1 will take care of the AjaxWrapper with id=1 and thus replace all the innerHTML of the first DIV when submitted. Therefore if the user filters the items, he will get a new list and a new more button.

The more- link with param idl=2,3 will take care of the AjaxWrapper with id=2 and id=3, when clicked. In case of the AjaxWrapper with id=2 the new content will be added to the innerHTML of the first DIV (e. g. the second page of the list). In case of the AjaxWrapper with id=3 the button itself will be replaced with an new one, which now contains the correct params to load the third page.

Lust but not least: don't forget to add the CSS-class ajax to all elements that are meant to trigger AJAX-events ;-)

That is basically all the magic.

Advanced usage options

On Submit

By default, a form is always sent "on change". This behavior can be changed to "on submit" by using the additional class "ajax-submit-only"

Scroll to top

To scroll to top after submit use class "ajax-scroll-top"

Loading indicator

As data-attribute you can specify the ID of the container that should be grayed out with "data-ajax-indicator-id"

Special Case I: Execute Ajax-Call on page-load

To achieve this you simply can add a template-tag to the website. The following example additionally checks for logged in users an ONLY executes the ajax call when one is logged in

If you combine this with a form, you can additionally check whether the form was submitted. This way, the ajax call is only triggered, when the form was not submitted. In that use-case it is also important to use the forward-method in case of an error in the controller, because the forward-methods keeps the POST-vars and thus prevents a further ajax-call.

Special Case II: Execute Ajax-Call on page-load with specific viewport only

In some cases it is helpful to bind the ajax-request on page-load to a specific viewport, e.h. to only trigger it on mobile devices. To archive this you can simply add the corresponding attribute data-ajax-max-width.

Additional hints

Since version v8.7.57-stable all requests are sent as "POST" to avoid the JS error "HTTP Error 414. The request URL is too long"


All versions of t3-ajax-api with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
ext-dom Version *
masterminds/html5 Version ^2.0
typo3/cms-core Version ~9.5.0 || ~10.4.0
madj2k/t3-core-extended Version ~9.5.4 || ~10.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package madj2k/t3-ajax-api contains the following files

Loading the files please wait ....