So Basically I am trying to get values from an HTML element (Inside Html element Data comes from database using java) and then these values I am sending to another page using Ajax on onClick event. Here is that HTML Element
<a href="#" onclick="getPosts(<%= sec.getId() %>, this,<%= sec.getDb_name()%>)" class="c-link list-group-item list-group-item-action"><%= sec.getSection() %></a>
Here is the function body.
function getPosts(postid,temp,db_name)
{
$("#loader").show();
$("#post-container").hide();
$(".c-link").removeClass('active')
$.ajax({
url: "load_data.jsp",
type:'POST',
data:{pid:postid, db:db_name},
success: function (data, textStatus, jqXHR) {
console.log(data);
$("#loader").hide();
$("#post-container").show();
$("#post-container").html(data);
$(temp).addClass('active')
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
}
})
}
I am calling this function using another JQuery method that is below
$(document).ready(function (e){
let allPostRef=$('.c-link')[0]
getPosts(0,allPostRef,"eng_a"); // here i do not know how to call this function
})
getPosts(0,allPostRef,"eng_a"); here I also do not know how to call this function means if I am sending only two parms values inside a function so it works fine but i had to manually give string values and it is not getting data although I have checked db_name values is retrieving fine inside the element.