简体   繁体   English

jQuery-Servlet发布异常失败

[英]JQuery - Servlet post fails erratically

I am new to JQuery, I am running into a wierd issue here, I try to do a post of my HTML form to a servlet, and try to print data on the servlet. 我是JQuery的新手,在这里遇到了一个棘手的问题,我尝试将HTML表单发布到servlet,并尝试在servlet上打印数据。 Data gets printed most of the times I submit the form (say 7 times out of 10) with new values. 在我提交表单时,大多数情况下都会打印数据(例如,十分之七)。 But It fails the other 3 times, I could not find a pattern at which this is failing. 但是它在其他3次失败,我找不到失败的模式。

I tried using firebug and chrome tool, I don't see an error on the console, and I get 200 response in the resources/HTML tool in chrome every time I submit the form with correct values set. 我尝试使用Firebug和chrome工具,但在控制台上看不到错误,并且每次我提交设置了正确值的表单时,chrome的资源/ HTML工具都会收到200条响应。

Here is my code 这是我的代码

HTML 的HTML

<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>   

<form id="fcall">
    <p> Start Date:  <input  type="text" name="start" id="ibox_start"> 
        End Date: <input type="text" name="end" id="ibox_end"> </p>
        <div id="buttonID"> 
     <input type="submit" value=" Find " class="button"></div>

</form>

main.js main.js

$().ready(

    function(){
        $('#ibox_start').datepicker();
        $('#ibox_end').datepicker();

        $('#fcall').submit(

         function(){

           var start =  $('#ibox_start').val();
           var end = $('#ibox_end').val();
           alert(start);

           $.post("DServlet", {start:start,end:end}, function(data) {});

          }
        );
      }         
    );          

Servlet Servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws      ServletException, IOException {
    // TODO Auto-generated method stub



    String start = request.getParameter("start");
    String end = request.getParameter("end");
    System.out.println("Date Recieved "+start);

 }

I would expect to see one of the following : 我希望看到以下之一:

  • natural HTML form submission 自然的HTML表单提交
  • natural HTML form submission with a submit handler which validates form values and returns either true to allow form submission or false to suppress it. 带有提交处理程序的自然HTML表单提交,该处理程序将验证表单值并返回true (允许表单提交)或false (禁止表单提交)。
  • a submit handler that submits form data by AJAX, establishes a .done() handler to handle the HTTP response, and returns false to inhibit natural HTML form submission. 一个通过AJAX提交表单数据的提交处理程序,建立一个.done()处理程序以处理HTTP响应,并返回false以禁止自然HTML表单提交。

The code above looks like a hybrid of these possibilities. 上面的代码看起来像是这些可能性的混合体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM