I'm having trouble calling an external function on success. The ideal solution would let me also pass in some parameters to the function!
i.e. success: writeToConsole("successful");
Javascript:
$(document).ready(function () {
$(".portalControls").find(".syncButton").click(triggerSync);
});
function triggerSync(e) {
e.preventDefault();
$.ajax({
type: "GET",
url: "sync",
dataType: "text",
success: writeToConsole,
error: writeToConsole
}
});
}
function writeToConsole(consoleText) {
$.find("portalConsole").text(consoleText);
}
HTML:
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/js/scripts.js"></script>
Errors I get: "Uncaught TypeError: $.ajax is not a function"
.
I never get the request on my server.
EDIT: Problem was to do with having a jQuery slim script on another page. Removing that fixed the error.