Use ajax from function.php

As Milo already said in comment, jQuery is in noConflict mode in WordPress. This way other JS libraries can also use $ character…

One way to solve it is using jQuery everywhere in your JS files.

Another is to create block and define $ variable in it:

jQuery(function ($) {

    $.ajax(...); // here you can use $ since it is already defined and won’t cause conflicts

});