I'm trying to set a default value for a function parameter, that will query my server for an initial value.
The end goal is i will be able to click on one of the list items I create to retrieve and create a new list.
<script type="text/javascript">
$(function getJobs(jobid=0) {
{#jobid = 0;#}
console.log("jobid: " + jobid);
let query = {id: jobid};
console.log(query);
$.getJSON("{% url 'website:get-jobs' %}", query, function (data) {
console.log("getjson");
$.each(data, function (key, value) {
console.log(key + " - " + value);
$('#jobs-list').append("<li id='" + key + "'" + "href='#'" + "onclick=getJobs(key)" + ">" + value + "</li>");
});
});
})
</script>
If I manually set jobid to 0(commented out in the code above) everything works perfectly. If i try to set it in the function parameter list i get this in my console.log: jobid: function(e,t){return new w.fn.init(e,t)}
$(function() { ... })) passes the jQuery global as the sole function argument, iejQuery(function(jQuery) { ... }). See api.jquery.com/jquery/#jQuery3jobidever not be0?