在 Chrome 開發者工具中出現 $.ajax is not a function 或 $ is not defined,通常是因為:
$ 符號,導致衝突。<script src="jquery.min.js"></script> 在所有使用 $ 的腳本之前載入。jQuery.ajax(...) 完整命名空間,或呼叫 var $j = jQuery.noConflict() 自訂別名。<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
<script>
jQuery.ajax({
url: '/api/data',
method: 'GET',
success: function(res) { console.log(res); }
});
</script>
養成「先載入庫、再撰寫業務邏輯」的習慣,並善用 noConflict() 避免符號衝突,即可杜絕此類錯誤。