jQuery通过HTML表单发布

时间:2016-01-27 10:48:18

标签: javascript jquery html

网站搜索了不同的网站,但我找不到我的表单/ html文件的解决方案。我真的很新,我真的不知道为什么我的代码不会工作,有些人可以检查我的代码并告诉我有什么问题吗? (这对我来说是学习它的最简单方法)

<!DOCTYPE html>
<html>
<head>
  <script src="jquery-1.9.1.js"></script>
</head>
<body>
    <form id="formoid" action="site" title="" method="post">
        <div>
            <label class="title">First Name</label>
            <input type="text" id="name" name="name" value="" >
        </div>
        <div>
            <label class="title">Name</label>
            <input type="text" id="name2" name="name2" value="">
            <input name="authenticity_token" type="hidden" value="token_value">
        </div>
        <div>
            <input type="submit" id="submitButton"  name="submitButton" value="Submit">
        </div>
 </form>
<script type='text/javascript'>
    /* attach a submit handler to the form */
    $("#formoid").submit(function(event) {

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

      /* Send the data using post */
      $.post( 'site/login', { 
                           authenticity_token: $('#authenticity_token').val(), 
                           username: $('#name').val(),
                           password: $('#name2').val()
                             },
                 function(responsePage,statusText,result)
                 {
                    console.log(responsePage);
                 } 
                );
    });
</script>

</body>
</html> 

感谢您的帮助:)!

1 个答案:

答案 0 :(得分:0)

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<style type="text/css">
    .selected{
        background-color : green;
    }
    </style>
<script>





    $(document).ready(function () {

        $("#formoid").submit(function (event) {

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

            /* Send the data using post */
            $.post('login_1.asp', {
                authenticity_token: $('#authenticity_token').val(), username: $('#name').val(), password: $('#name2').val()
            },
                       function (responsePage, statusText, result) {
                           alert("response from server---" + responsePage);
                       }
                      );
        });
    });




</script>
</head>
<body>
   <form id="formoid" action="site" title="" method="post">
        <div>
            <label class="title">First Name</label>
            <input type="text" id="name" name="name" value="" >
        </div>
        <div>
            <label class="title">Name</label>
            <input type="text" id="name2" name="name2" value="">
            <input name="authenticity_token" type="hidden" value="token_value">
        </div>
        <div>
            <input type="submit" id="submitButton"  name="submitButton" value="Submit">
        </div>
 </form>
</body>
</html>

login_1.asp

<%

    Response.Write  request.Form("username") + "---------------" +  request.Form("password") 
     %>