Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to override Content-Type header #1906

Merged
merged 6 commits into from
Nov 16, 2023
Merged

Conversation

gbourant
Copy link
Contributor

I'm using a 3rd party js library (openstreetmap) which returns me a veryComplexObject which i need to make an ajax request. At the moment htmx.ajax overwrites the Content-Type. With this commit we can do use any Content-Type we want.

htmx.ajax('POST',"/map", {
        target:'#myTarget',
        swap:'morph:innerHTML',
        headers: {
            'Content-Type': 'application/json'
        },
        values: JSON.stringify(veryComplexObject)
})

This works great. But it would be cool if we had more control over of some (if not all) htmx properties like hx-push-url.

Copy link
Collaborator

@alexpetros alexpetros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need a couple tests to validate the new and old behavior.

src/htmx.js Show resolved Hide resolved
@alexpetros alexpetros added bug Something isn't working and removed enhancement New feature or request labels Nov 5, 2023
@alexpetros alexpetros changed the title allow to send other Content-Type via htmx.ajax Allow user to override Content-Type header Nov 5, 2023
@gbourant
Copy link
Contributor Author

gbourant commented Nov 5, 2023

We also need a couple tests to validate the new and old behavior.

I will add them within the next week

@alexpetros
Copy link
Collaborator

Oh, also, needs to be retargeted against dev please

@gbourant
Copy link
Contributor Author

gbourant commented Nov 7, 2023

Oh, also, needs to be retargeted against dev please

Yeap, i will change that after we find a solution.

@gbourant gbourant changed the base branch from master to dev November 8, 2023 18:14
@Telroshan Telroshan added the ready for review Issues that are ready to be considered for merging label Nov 8, 2023
@alexpetros alexpetros removed the ready for review Issues that are ready to be considered for merging label Nov 8, 2023
Copy link
Collaborator

@alexpetros alexpetros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove the two unrelated changes (@Telroshan is correct about splitting up unrelated PRs) and then we're good to go.

@@ -58,7 +58,7 @@ or
* `handler` - a callback that will handle the response HTML
* `target` - the target to swap the response into
* `swap` - how the response will be swapped in relative to the target
* `values` - values to submit with the request
* `values` - values to submit with the request (json object, not an array)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one as well

src/htmx.js Outdated
@@ -3301,7 +3302,7 @@ return (function () {
});
});
triggerEvent(elt, 'htmx:beforeSend', responseInfo);
var params = useUrlParams ? null : encodeParamsForBody(xhr, elt, filteredParameters)
var params = useUrlParams ? null : encodeParamsForBody(xhr, elt, filteredParameters);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change

@alexpetros
Copy link
Collaborator

Terrific, thank you!

@alexpetros alexpetros added the ready for review Issues that are ready to be considered for merging label Nov 8, 2023
@1cg 1cg merged commit 6a9a861 into bigskysoftware:dev Nov 16, 2023
1 check passed
@1cg
Copy link
Contributor

1cg commented Nov 16, 2023

beauty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready for review Issues that are ready to be considered for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants