eventpreventDefault()无法正常工作我需要在同一页面上显示结果

时间:2017-11-28 01:32:36

标签: java jquery html

我已经在html中为表单添加了java脚本文件,并且它连接到我希望在提交之后在同一页面上显示数据的java文件,即index.html但是在提交之后它将我带到注册页面。



html>
    <head>
	<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <title>Register form</title>
	</head>
    <body>
        <form method="post" action="register">
        Name:<input type="text" name="name" /><br/>
        Email ID:<input type="text" name="email" /><br/>
        Password:<input type="text" name="pass" /><br/>
        <input type="submit" value="submit" />
		<script type='text/javascript'>
    /* attach a submit handler to the form */
    $("#register").bind('submit',(function(event) {

      /* stop form from submitting normally */
      event.preventDefault();

      /* get the action attribute from the <form action=""> element */
      var $form = $( this ),
          url = $form.attr( 'action' );

      /* Send the data using post with element id name and name2*/
      var posting = $.post( url, { name: $('#name').val(), email: $('#email').val(),pass: $('#pass').val() } );

      /* Alerts the results */
      posting.done(function( data ) {
        alert('success');
      });
    });
</script>
        </form>
    </body>
	
	
	
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案