ajax POST处理程序循环


ajax POST handler looping

我试图设置一个基本的ajax提交处理程序来修改表单(我正在编写关于CSRF漏洞的课程),但页面不断循环。下面是我一直在修改的示例代码,它基于http://api.jquery.com/jQuery.post/:

 <!DOCTYPE html>
 <html>
 <body>
 <form id="hidden_form" target="blahblah.com"> </form>
 <script>
 //Attach a submit handler to the form
 $( '#hidden_form' ).submit(function( event ) {
      //stop form from submitting normally
      event.preventDefault();
      //set new target for the form
      var $form = $( this ),
        url = "http://192.168.101.250/mutillidae/index.php?page=add-to-your-blog.php&csrf-token=SecurityIsDisabled&blog_entry=example+text&add-to-your-blog-php-submit-button=Save+Blog+Entry"
      //capture the response but do nothing with it
      var posting = $.post( url );
 });
 </script>
 <script>
      $( '#hidden_form' ).submit();
 </script>
 </body>
 </html>

当我用浏览器在本地加载这个文件时,选项卡标签在/path/to/file.html和"Connecting"真的很快,但我知道请求从来没有被发送出去,因为我有打嗝代理拦截所有流量,它没有捕获任何东西。

我做错了什么?我希望ajax处理程序发送POST请求到指定的url,但它永远不会被发送出去

编辑:我已经改变了第二个脚本调用处理程序,而不是实际的形式,但仍然没有在网上发送流量?

直接在表单元素节点上调用.submit()不会触发提交事件,相反,它会绕过所有事件处理程序直接提交表单。你应该调用触发事件处理程序的方法的jQuery形式。

$( '#hidden_form' ).submit();