imacrayon / alpine-ajax

An Alpine.js plugin for building server-powered frontends.
https://alpine-ajax.js.org
MIT License
558 stars 11 forks source link

Question: Fetch and headers #74

Closed eydun closed 3 months ago

eydun commented 3 months ago

Thanks for this awesome project.

I am using some server-side php-code that checks if the request is made by ajax, by examining if 'X-Requested-With' is set to 'XMLHttpRequest' in headers.

Is it possible to add values to the headers, when using Alpine-Ajax?

imacrayon commented 3 months ago

Yes, you can use the x-header directive to set headers per request or the headers key in the global config to set the same header for every request.

Every AJAX request also includes the X-Alpine-Request: true and X-Alpine-Target: {target ids} headers by default.

eydun commented 3 months ago

Thanks! I will look into using the global config setting for this.