The file is within .php ext and it's in the WordPress template page. When I put variable to get URI to $.post request it just doesn't work. However, if I replace vurl with absolute url, it totally works. The code looks okay to me or am I missing something? If someone can shed light on this.
jQuery(document).ready(function() {
$('#player').on('input', function() {
var searchKeyword = $(this).val();
if (searchKeyword.length >= 2) {
var vurl = '<?= get_template_directory_uri(); ?>';
$.post('"+vurl+"/others/goals.php', { keywords: searchKeyword }, function(data)
{
$('ul#cf').empty()
$.each(data, function(ding, dong) {
$("ul#cf").append('<a><li id="'+ dong.id +'"> ' + dong.title+ '</li></a>');
$('ul#cf').on('click','li',function(){
$('#player').val(this.id);
});
});
}, "json");
}
});
});