Show More button pagination, AJAX/jQuery/JAVA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ReA1
    New Member
    • Aug 2013
    • 6

    Show More button pagination, AJAX/jQuery/JAVA

    I have a function, say A() that calls some elements from the database depending on the range provide.
    What I want to do is, on the UI, there is a 'Load More' button, which when clicked, displays next set of items, by calling the above function A() by making an AJAX call using jQuery.
    I went through some forums, but was not able to get a clear understanding of how to do it.

    Thank you
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it all depends on how you select the elements out of the DB. if (e.g.) you use a LIMIT clause and pass the amount of sets and a starting number, you simply need to increase the starting number parameter in the AJAX call.

    Comment

    • ReA1
      New Member
      • Aug 2013
      • 6

      #3
      Ya, but what I want to know is, like I mention the URL in the AJAX call which calls the corresponding controller function. Now that function sends an Object as a result, and I want only certain fields of that object to be merged with the original html table that was created during the page loading. How do I do that?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        impossible to say without code.

        Comment

        • ReA1
          New Member
          • Aug 2013
          • 6

          #5
          Code:
          myFunction(){
              $   .ajax({							
          type:POST',				
          url : 'myURL',
          no the URL controller that will be executed, will return the Object.
          I already have a table,
          Code:
          <fieldset>
                  <table>
                      <tbody>
                          <c:forEach var="box" items="${boxItems}">
                               <tr>
                                  <td width="10%">
                                      <div id="boxDetails">
                                          <a //some data;</a>
                                      </div>
                                  </td>
                                  <td width="30%">
                                      <c:out value= //some value" />
                                  </td>
                                  <td width="30%">
                                     <span //some value
                                     </span>
                                  </td>
                                  <td width="30%">
                                  </td>
                              </tr>
                              <c:forEach items="${boxChanges}" var="property" varStatus="status" >
                                  <tr>
                                     <td width="10%">
                                     </td>
                                     <td width="30%">
                                         <c:out value="${item.key}" escapeXml="false"/>
                                     </td>
                                     <td width="30%">
                                         <c:out value="${item.value.oldValue}" escapeXml="false"/>
                                     </td>
                                     <td width="30%">
                                         <c:out value="${item.value.newValue}" escapeXml="false"/>
                                     </td>
                                  </tr>
                              </c:forEach>
                          </c:forEach>
                      </tbody>
                  </table>
              </fieldset>
          Now, I want to append similar table by having AJAX call to this table creating during the first call.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            is this a server-side or a client-side template?

            Comment

            • ReA1
              New Member
              • Aug 2013
              • 6

              #7
              It will be a client side template.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                then you just need to run that template again, only with more data.

                Comment

                • ReA1
                  New Member
                  • Aug 2013
                  • 6

                  #9
                  you want to say,
                  ("#divID").appe nd("#divID")
                  Is it the way to do it?

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    I do not know how your template works, so I can’t say.

                    however, duplicating content (that’s what your code applies) is certainly not what you want, esp. if you duplicate IDs which must be unique by definition.

                    Comment

                    • ReA1
                      New Member
                      • Aug 2013
                      • 6

                      #11
                      Could you help me with this?

                      I have the following code in jsp,
                      <c:out value="${fn:rep lace(getData, '@something', '')}"

                      How do I write it in JavaScript?

                      Basically how can we replace <c:out> in javascript?

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        JSP, ain’t that Java?

                        Comment

                        • RockybBalboa
                          New Member
                          • Feb 2018
                          • 5

                          #13
                          You can use jQuery AJAX Method here to call a server side page (PHP page).

                          This PHP method will call and fetch new values form the database and return them to the .ajax() method. Then you can simply append them to your ul element.

                          Below is the explanation of jQuery .ajax() method:

                          Code:
                          $.ajax({
                              type: "POST",
                              url: "jquery-ajax-subscribe.php", // php page
                              data: {newcontent: 10}, // pass parameter to fetch new content from database
                              success: function (msg) {
                                  //append them to your ul element.
                              },
                              error: function (req, status, error) {
                                  alert("Some error");
                              }
                          });
                          Last edited by Rabbit; Feb 1 '18, 05:39 PM. Reason: Removed link

                          Comment

                          Working...