Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ajax和Servlet填充文本框_Ajax_Jsp_Servlets - Fatal编程技术网

使用Ajax和Servlet填充文本框

使用Ajax和Servlet填充文本框,ajax,jsp,servlets,Ajax,Jsp,Servlets,我正在尝试使用Ajax从Servlet到JSP的输入框获取一个值。我已设法将该值输入到警报框中。但当我试图将该值输入到输入框中时,它没有起作用。请参阅以下代码 这是AjaxtSetServlet protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { respo

我正在尝试使用Ajax从Servlet到JSP的输入框获取一个值。我已设法将该值输入到警报框中。但当我试图将该值输入到输入框中时,它没有起作用。请参阅以下代码

这是AjaxtSetServlet

  protected void processRequest(HttpServletRequest request, HttpServletResponse    response)
        throws ServletException, IOException
   {
    response.setContentType("text/html");

    String text = "some text";
    response.setCharacterEncoding("UTF-8");

    response.getWriter().write(text);
}
这里是id为firstName的输入框所在的位置

<button type="button" class="close" data-dismiss="modal" aria-

hidden="true">&times;</button>
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header"> <a href="#" data-dismiss="modal"> <img src="images/arrow-back-512.png"  width="30px" height="30px"> <small>Back</small></a> <span id="myModalLabel" style="margin-left:20px;"><font size="+2"><b>Edit New Member</b></font></span> </div>
      <div class="modal-body">
          <form class="form-horizontal" method="post" action="EditOnlySrvlt?idEmployee=<%=request.getParameter("idEmployee")%>"" >
          <fieldset id="modal_form">

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="textinput">First Name</label>
              <div class="col-md-6">
                <input  name="firstName" id="firstName" type="text"  class="form-control input-md" >
              </div>
            </div>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="textinput">Middle Name</label>
              <div class="col-md-6">
                <input  name="middleName" type="text" class="form-control input-md"> 
              </div>

            </div>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="textinput">Last Name</label>
              <div class="col-md-6">
                <input  name="lastName" type="text" class="form-control input-md"> 
              </div>

            </div>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="textinput">Date Of Birth</label>
              <div class="col-md-6">
                <input  name="dateOfBirth" type="date" class="form-control input-md"> 
              </div>

            </div>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="textinput">Passport Number</label>
              <div class="col-md-6">
                <input  name="passportNumber" type="text" class="form-control input-md"> 
              </div>

            </div>



      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Edit</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      </div>
                </fieldset>
        </form>

    </div>
  </div>
</div>
</div>

<!-- /Edit Job modal -->
这是剧本

 <script>
 $(function() {
//twitter bootstrap script
 $("tr#somebutton").click(function(){

 $.get("ajaxTestSrvlt", function(responseText) { // Execute Ajax GET request on URL of "someservlet" and execute the following function with Ajax response text...
     $('#firstName').text(responseText) ;       // Locate HTML DOM element with ID "somediv" and set its text content with the response text.
});

});
});
</script>  

如果是输入,你应该给出

$('#firstName').val(responseText);

请尝试$'firstName'.valJSON.stringifyresponseText;在click函数中尝试alertHi,我认为您在执行click fn时出错