.post()问题不正确



,所以我有一个小的链接器,我正在尝试进行工作,当用户输入其用户名和密码时,它将连接到本网站而不实际离开页面,但是很难做到这一点。我正在使用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>

感谢您的帮助!

这是由文档上的JavaScript错误引起的,使您的代码无法正常工作。

对于Debug,请在发布后的代码末尾添加return false;。或尝试设置其他按钮发射提交。喜欢

$("#someButtonButNutSubmit").click(function(){
var $form = $( this ),
        term = $form.find( 'input[name="__EVENTTARGET"]' ).val(),
....
});

检查为什么您的JavaScript/jQuery失败了。检查浏览器控制台日志以获取详细信息

最新更新