如何在 java Web 应用程序中使用 Ajax 将文本字段的值与 href 值一起带到下一页

How do I take the value of textfield along with the href value to the next page using Ajax in java web app?

本文关键字:字段 href 一起 一页 文本 Web java 应用程序 Ajax      更新时间:2023-09-26

我在java Web应用程序中使用Ajax,我想将textfield的值与href链接一起带到下一页。

<%@page contentType="text/html" pageEncoding="UTF-8"%>
           <% String root = getServletContext().getContextPath();
           %>
              <table  border="0" id="box-table-b">
                  <thead><tr>
                  <th height="31" colspan="2" nowrap>Enter User Id of Patient </th>
                      </tr></thead>
                <tr>`enter code here`
                  <td width="76" nowrap>UserId</td>
                  <td width="85"  nowrap>
                      <input type="text" name="confuserid" id="confuserid"/>
                 </td>
                </tr>
                <tr>
                <td height="66" colspan="2" align="center" valign="middle" nowrap>            
                <a href="#" onclick="returndisplayData('<%=root%>/confapp.do?method=confapp','entry');"><input type="button" value="Submit"></a>
                  </td>
                </tr>
              </table>

您可以将控件和链接放在表单中,然后通过 GET 提交表单,但这会使您远离 ajax。

另一种选择是简单地使用 jQuery 获取 confuserid 的值,并将其附加到您传递给 returndisplayData 函数的 URL。

类似的东西

function getMyURL() {
    return '<%=root%>/confapp.do?method=confapp&confuserid='+$("#confuserid").val();
}

那么你的链接看起来像

<a href="#" onclick="returndisplayData(getMyURL(),'entry');"><input type="button" value="Submit"></a>

显然,您需要在页面中包含jQuery。