开发者

Submit the form using jquery and use the result as it returns as request atttribute

Can I submit a request through jquery using $.get and use the returned result as it returns from normal submition to server,

here's what I mean, I want to make page navigator for all users in the system, I want to show 10 users per page, for the first time I request the page, the servlet returns 10 users and I show then like this

 <c:forEach items="${requestScope.AllUsers}" var="user" varStatus="loop">
        <tr class="userRow">
            <td class="numberWidth">${loop.index + 1}</td>
            <td class="nameWidth user" id="${user.userno}">${user.fullName}</td>
            <td>
                <c:choose>
                    <c:when test="${user.active == true}">
                        <button name="DeactivateBtn"  id="deactivate" class="deactivate btn">تعطيل</button>
                    </c:when>
                    <c:when test="${user.active == false}">
                        <button name="ActivateBtn" id="activate" class="activate btn">تفعيل</button>
                    </c:when>
                </c:choose>
            </td>
        </tr>
    </c:forEach>

when user click on the next page button, I sent request to servlet through开发者_如何学JAVA jQuery

var param = {
    "page": "ViewUsers",
    "from": page_index * items_per_page,
    "to": (page_index * items_per_page) + items_per_page
};
$.get("InstitutionManagementServlet",param);

and it calls the same method that returns different users depending on the range I sent, the problem is that, for second request to servlet the users are not appear as the first time, even in consol shows that the return list has users values?

Does that have a concern of sending request using jquery???


Here,

$.get("InstitutionManagementServlet",param);

You are not handling the response of the request at all. A callback function is missing. So whatever the servlet is returning is totally ignored. You need to add a callback function to handle the response:

$.get("InstitutionManagementServlet", param, function(response) {
    // Handle response here. E.g., insert retrieved data in the desired place.
});

See also:

  • jQuery.get() API documentation
  • How to use Servlets and Ajax?

Update: so, you actually want to send a synchronous GET request using JavaScript (e.g. changing the current page location altogether)? You can use window.location for this.

window.location = "InstitutionManagementServlet?" + $.param(param);

See also:

  • window.location MDC documentation
  • jQuery.param() API documentation
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜