Skip to content

Decouple AJAX calls in JS logic and remove unnecessary return values from AJAX endpoints #131

Description

@felixarntz

Is your enhancement related to a problem? Please describe.

Currently, all AJAX calls made from the admin JS file are chained directly to each other, with the response data from one request being passed as data to the next. This has led to an awkward requirement where we have to return certain data from the PHP AJAX endpoints just because the next endpoint needs them rather than because it actually makes sense to return them from the endpoint. We should avoid that and truly decouple the AJAX endpoints.

We should decouple all the functions in JS so that they don't just accept a data "dump" parameter, but individual parameters for what they truly need. For example:

  • getChecksToRun( plugin ): Its AJAX endpoint should return just the check slugs, and then they should be put into a variable.
  • setUpEnvironment( plugin, checks ): Its AJAX endpoint should return just a success message, nothing else.
  • runChecks( plugin, checks ): AJAX endpoint is already good as is, just the JS function should have the new cleaner signature.
  • cleanUpEnvironment(): Can basically remain as is.

Another good idea that we could include here would be to make a wrapper around the fetch function since we always call it the same way, e.g. fetchAJAX( data ), which includes the ajaxurl, method: 'POST' and credentials: 'same-origin' bits, and it could also automatically include the nonce in the body data since that needs to be present in every request.

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions