Skip to content

Commit

Permalink
Add beforeAjaxSend.ic event
Browse files Browse the repository at this point in the history
  • Loading branch information
Carson Gross committed Jan 14, 2016
1 parent 6678900 commit b965176
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/intercooler.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ var Intercooler = Intercooler || (function() {
ajaxSetup.processData = false;
ajaxSetup.contentType = false;
}

$(document).trigger("beforeAjaxSend.ic", ajaxSetup);

$.ajax(ajaxSetup)
}

Expand Down
23 changes: 23 additions & 0 deletions test/unit_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,29 @@ <h4>Test HTML</h4>
</script>


<button id="reqhandler-btn-1" ic-get-from="/reqhandler_start"></button>

<script>
intercoolerTest("Test beforeAjaxSend.ic can modify ajax setup", function (assert) {

$(document).on("beforeAjaxSend.ic", function(evt, settings){
if(settings['url'] == "/reqhandler_start") {
settings['url'] = "/reqhandler_end"
}
});
$.mockjax({
url: "/reqhandler_end",
responseText: "foo"
});
$('#reqhandler-btn-1').click();
},
function (assert) {
assert.equal($("#reqhandler-btn-1").text(), "foo");
});
</script>



</div>
</body>
</html>
9 changes: 9 additions & 0 deletions www/_includes/events_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
DOM elements.)
</td>
</tr>
<tr>
<td>
<code>beforeAjaxSend.ic(evt, settings)</code>
</td>
<td>
Fired on the document before every AJAX request, allowing you to modify the settings object (e.g. to add
or remove parameter or headers, change content types, etc.)
</td>
</tr>
<tr>
<td>
<code>beforeHeaders.ic(evt, elt, xhr)</code>
Expand Down

0 comments on commit b965176

Please sign in to comment.