.post()的问题无法正常阅读

时间:2012-10-24 02:47:22

标签: jquery

所以我有一个小链接器,我正在努力工作,当用户输入他们的用户名和密码时,它将连接到这个网站而不会实际离开页面,但这样做有些困难。我在jquery中使用.post()发送到aspx.page。

当我点击提交时,我会被发送到网站,我不希望这样,加上它不会登录。

代码 -

<div class="linkdimesAccount">



                    <form name="aspnetForm" method="post" action="http://1betvegas.com/default.aspx" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_MainContent_ctlLogin_BtnSubmit')" id="aspnetForm" style="margin: 0 0 0 0;">
            <script type="text/javascript">
                //<![CDATA[
                var theForm = document.forms['aspnetForm'];
                if (!theForm) {
                    theForm = document.aspnetForm;
                }
                function __doPostBack(eventTarget, eventArgument) {
                    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
                        theForm.__EVENTTARGET.value = eventTarget;
                        theForm.__EVENTARGUMENT.value = eventArgument;
                        theForm.submit();
                    }
                }
                //]]>
                </script>
             <div>
            <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="">
            <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="">
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="eYjk1H7gGdxNJmuevBY9L0vo1lS2NWgmApCJFEQznQr+AwZaPf/hYV4iGSnPCSknyHjESN/BgHueeChVuGgmN4wtWFCdUaYPJRItirNF0nIBHe9Q">
            </div>
            <script src="/WebResource.axd?d=FrT3YL7-WvrI_DKD4vsDo2d0Al_8j_u_HUym76C9Z5ggdJlIe1yu5cWI_jZDYcizjTU0SkefrocS8ATa0&amp;t=634604245351482412" type="text/javascript"></script>
            <div>

                <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="yepc3zJ4Kjr5ru/aXm+s9SqYXyFoM+cwIlWPI69lDMnO4eybZJ1cM1pfzowM47Ggezne5505JNUx/VGe3XO8OCmvZnghqv8ZCuJm+yffjs4inz2n6ctjK/0F/qER0ARSznB8iJsMIZ7HxPXA/Stv+0ubH0U=">
            </div>
            <h2>Link your 5dimes account</h2>

                <table>
                    <tr>
                    <?php
                    if ($dimesaccount == 1){
                    echo "<h2 style='color:red;'> Please note your account is already linked.  If password or other information has changed please re-enter your username and password";
                    }
                    ?>
                        <td>
                        Username:
                        </td>
                         <td>
                            <input name="ctl00$MainContent$ctlLogin$_UserName" type="text" size="15" id="ctl00_MainContent_ctlLogin__UserName" accesskey="u" tabindex="60" class="login_input">
                        </td>
                    </tr>
                    <tr>
                     <td>
                        Password:
                        </td>
                    <td>
                        <input name="ctl00$MainContent$ctlLogin$_IdBook" type="hidden" id="ctl00_MainContent_ctlLogin__IdBook">
                        <input name="ctl00$MainContent$ctlLogin$Redir" type="hidden" id="ctl00_MainContent_ctlLogin_Redir" value="wager/welcome.aspx">
                        <input name="ctl00$MainContent$ctlLogin$_Password" type="password" size="15" id="ctl00_MainContent_ctlLogin__Password" accesskey="p" tabindex="61" class="login_input">
                    </td>
                    </tr>
                    <tr>
                    <td>
                        <input type="submit" name="ctl00$MainContent$ctlLogin$BtnSubmit" value="Link" id="ctl00_MainContent_ctlLogin_BtnSubmit" class="login_input" style="text-transform: uppercase;">
                    </td>
                    </tr>

                </table>


        </div><!-------.linkdimesAccount ------>
        </form>
        <div id="result"></div>
        <script>
  /* attach a submit handler to the form */
  $("#aspnetForm").submit(function(event) {

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

    /* get some values from elements on the page: */
    var $form = $( this ),
        term = $form.find( 'input[name="__EVENTTARGET"]' ).val(),
        term1 = $form.find( 'input[name="__EVENTARGUMENT"]' ).val(),
        term2 = $form.find( 'input[name="__VIEWSTATE"]' ).val(),
        term3 = $form.find( 'input[name="ctl00$MainContent$ctlLogin$_UserName"]' ).val(),
        term4 = $form.find( 'input[name="ctl00$MainContent$ctlLogin$_IdBook"]' ).val(),
        term5 = $form.find( 'input[name="ctl00$MainContent$ctlLogin$Redir"]' ).val(),
        term6 = $form.find( 'input[name="ctl00$MainContent$ctlLogin$_Password"]' ).val(),
        term7 = $form.find( 'input[name="ctl00$MainContent$ctlLogin$BtnSubmit"]' ).val(),

        url = $form.attr( 'action' );

    /* Send the data using post and put the results in a div */
    $.post( url, { s: term, s: term1, s: term2, s: term3, s: term4, s: term5, s: term6, s: term7 },
      function( data ) {
          var content = $( data ).find( '#content' );
          $( "#result" ).empty().append( content );
      }
    );
  });
</script>

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

这是由于您的文档上的javascript错误导致您的代码无法正常运行。

用于调试尝试在发布后在代码末尾添加return false;。 或尝试设置其他按钮以解除提交。像

$("#someButtonButNutSubmit").click(function(){

var $form = $( this ),
        term = $form.find( 'input[name="__EVENTTARGET"]' ).val(),
....

});

检查JavaScript / jQuery失败的原因。检查浏览器控制台日志以获取详细信息