You have to put the name of your wp ajax action in your data when you do the ajax call.
I assume the ajax url is correct.
jQuery( document ).ready(function(){
//alert("Jquery Loaded");
jQuery("#pub_search").click(function(){
alert("You clicked");
event.preventDefault();
var term= $("#sterm").val();
console.log('your term send: '+term);
var data = {'nwterm': term, 'action': 'litsearch'}
$.get(litsearch.ajaxurl, data, function(data){
$("#container").html(data.response);
});
});
});
Also because you want to put a response in your html code you have to send something back from server.
Test.php
<?php
class Testclass{
function infotext(){
$txt="This is a ajax response text";
return $txt;
}
}
?>
Pub.php
<?php
function litsearch(){
$newterm = $_GET['nwterm'];
$newtest = new Testclass();
$data = array();
if($newterm == $_GET['nwterm']){
include('test.php');
$newtest = new Testclass();
$data['response'] = $newtest->infotext();
}
wp_send_json( $data );
}
add_action('wp_ajax_litsearch', 'litsearch');
add_action('wp_ajax_nopriv_litsearch', 'litsearch');
?>