When you call loadTeachers()
on DOMReady the context of this
will not be the #CourseSelect
element.
You can fix this by triggering a change()
event on the #CourseSelect
element on load of the DOM:
$("#CourseSelect").change(loadTeachers).change(); // or .trigger('change');
Alternatively can use $.proxy
to change the context the function runs under:
$("#CourseSelect").change(loadTeachers); $.proxy(loadTeachers, $('#CourseSelect'))();
Or the vanilla JS equivalent of the above, bind()
:
$("#CourseSelect").change(loadTeachers); loadTeachers.bind($('#CourseSelect'));
Related Posts:
- Cross-Origin Read Blocking (CORB)
- syntax error: unexpected token <
- Infinite Scrolling in Asp.Net MVC with jQuery / AJAX Issues
- ajax jquery simple get request
- jQuery get textarea text
- jQuery AJAX cross domain
- Set timeout for ajax (jQuery)
- How to generate a simple popup using jQuery
- What does on() in JavaScript do?
- jQuery AJAX submit form
- jQuery Ajax File Upload
- How can I upload files asynchronously with jQuery?
- Adding images to a Bootstrap Carousel with AJAX
- AJAX response error: net::ERR_EMPTY_RESPONSE
- Access Control Request Headers, is added to header in AJAX request with jQuery
- jQuery Ajax POST example with PHP
- Refresh/reload the content in Div using jquery/ajax
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- How to manage a redirect request after a jQuery Ajax call
- FormData append not working
- Download a file by jQuery.Ajax
- Ajax success function
- AJAX not Working with php as supposed
- How do I redirect to another webpage?
- Uncaught ReferenceError: jQuery is not defined [duplicate]
- How do I check whether a checkbox is checked in jQuery?
- Error OPTIONS net::ERR_CONNECTION_REFUSED
- Uncaught ReferenceError: jQuery is not defined [duplicate]
- Cannot read property ‘push’ of undefined when combining arrays
- Check if checkbox is checked with jQuery
- How can I get the data-id attribute?
- document.getElementById vs jQuery $()
- How to import jquery using ES6 syntax?
- How to filter an array/object by checking multiple values
- Uncaught SyntaxError: Invalid or unexpected token
- My javascript is returning this error: $.ajax is not a function
- What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})
- How can I print using JQuery
- Unable to preventDefault inside passive event listener
- Loading local JSON file
- jQuery $.cookie is not a function
- How to check all checkboxes using jQuery?
- Setting background-image using jQuery CSS property
- Uncaught TypeError: Cannot read property ‘msie’ of undefined – jQuery tools
- Scroll Automatically to the Bottom of the Page
- How do I check if string contains substring?
- How can I select an element by name with jQuery?
- keycode 13 is for which key
- jQuery disable/enable submit button
- What does window.jQuery and window.$ mean?
- Execute PHP function with onclick
- Dynamically load JS inside JS
- Uncaught TypeError: Cannot read property ‘appendChild’ of null
- JQuery issue “TypeError: $.getJSON is not a function”
- How to add an object to an array
- Convert CSV data into JSON format using Javascript
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- Extract hostname name from string
- how to get the value of a textarea in jquery?
- How can I get form data with JavaScript/jQuery?
- JQuery get the title of a button
- Trying to load jquery into tampermonkey script
- Preloading images with jQuery
- Uncaught SyntaxError: Unexpected token with JSON.parse
- TypeError getElementsByTagName is not a function issue
- How to open a Bootstrap modal window using jQuery?
- window.location.replace() not working to redirect browser
- How to check if the URL contains a given string?
- Check if url contains string with JQuery
- stopPropagation vs. stopImmediatePropagation
- How can I exit from a javascript function? [duplicate]
- Object doesn’t support property or method ‘addEventListener’
- How to fix javascript .toFixed is not a Function error
- jQuery checkbox checked state changed event
- $http.get(…).success is not a function
- etect the Enter key in a text input field
- Enable Submit Comment Without Page Reload (Using Ajax)?
- WordPress 5.5 – ReferenceError: commonL10n is not defined error
- Ajax call does not activate callback function
- Adding wp_ajax to a theme outside functions.php (on specific template page)
- WordPress AJAX Call Not Return Result
- How to create popup same as wordpress popup feature
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- wp_ajax unauthenticated and authenticated
- WordPress ajax function parameter value not being passed
- WordPress customizer refresh screen after save
- How to test nonce with AJAX – Plugin development
- How to set callback to execute after all the tinyMCE editors have been initialized?
- How do I make my wordpress post appear in a mouse hover preview?
- Is there some jQuery conflict here?
- javascript onClick update user_meta from jquery.ajax
- How to use wp_ajax_set_post_thumbnail?
- React to AJAX adding to the page
- Multiple Notifications SetInterval
- number of posts with “Load More”
- Use one javascript variable into another javascript file
- Widget won’t work due to old JavaScript? Any ideas how to make it work? [closed]
- Uncaught ReferenceError: tippy is not defined
- Error – Uncaught TypeError: e.dispatchEvent is not a function
- AJAX call not initializing for non-admins in WordPress