Add support for 304 response code in addition to the 204 response code

This commit is contained in:
carson 2020-09-07 10:06:35 -06:00
parent 278b5f1196
commit d5f6ef2900
2 changed files with 13 additions and 2 deletions

View File

@ -1579,8 +1579,8 @@ return (function () {
if (this.status === 286) {
cancelPolling(elt);
}
// don't process 'No Content' response
if (this.status !== 204) {
// don't process 'No Content' or 'Not Modified' response
if (this.status !== 204 && this.status !== 304) {
if (!triggerEvent(target, 'htmx:beforeSwap', eventDetail)) return;
var resp = this.response;

View File

@ -240,6 +240,17 @@ describe("Core htmx AJAX Tests", function(){
btn.innerHTML.should.equal("Click Me!");
});
it('handles 304 NOT MODIFIED responses properly', function()
{
this.server.respondWith("GET", "/test", [204, {}, "No Content!"]);
var btn = make('<button hx-get="/test">Click Me!</button>');
btn.click();
btn.innerHTML.should.equal("Click Me!");
this.server.respond();
btn.innerHTML.should.equal("Click Me!");
});
it('handles hx-trigger with non-default value', function()
{
this.server.respondWith("GET", "/test", "Clicked!");