2

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>
function call inside onClick is getPosts(int, element reference, string) when I gave function only two param getPost(int, ref) it works fine (sending values to another page) but I need database names too that with a string value and then function didn't even work getPosts(int, element reference, string).

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.

Hamdan Ali
  • 53
  • 9

0 Answers0