简体   繁体   English

将Javascript(Jquery)函数重定向到首页

[英]Redirect Javascript (Jquery) function to homepage

I need to redirect the following JS snippet, to http://localhost/homepage at the end of $('form').submit(); 我需要将以下JS代码段重定向到$('form').submit();结尾的http://localhost/homepage $('form').submit(); How can I do it ? 我该怎么做 ?

<script>
  //<![CDATA[
    $(document).ready(function() {
      $('#myModal .btn.btn-primary').click(function() {
        $('#myModal').modal('hide');
        $('form').submit();
      });
    });
  //]]>
</script>

the html involved is here : 所涉及的html在这里:

<div class='modal' id='myModal'>
  <div class='modal-header'>
    <div class='close'><a href="/">x</a></div>
    <h3>Add Tags</h3>

  </div>
  <div class='modal-body'>
    <form accept-charset="UTF-8" action="/tagging" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="7x2CSQ5spL32f1rjCJd5MdwYO6uZ+IwVsLEQ9ZB/Xcc=" /></div>
        <input id="tags_string" name="tags_string" type="text" value="zoz" />
        <input id="id" name="id" type="hidden" value="4f1c95e51d41c80ff20003f0" />
        <div class='modal-footer'>
          <!-- .btn.btn-primary= submit_tag "Add tag" -->
          <a class='btn btn-primary'>
            <input class='hidden' name='commit' type='submit' value='Add Tag'>

          </a>
        </div>
    </form>
  </div>
</div>

when you submit the form, it stops processing, it goes to the page where the form's 'action' directs (in your example, whatever page runs at /tagging) and that's it. 当您提交表单时,它将停止处理,它会转到表单的“操作”所指向的页面(在您的示例中,任何在/ tagging上运行的页面)就是这样。 If you want to do any redirection it'll have to do in the /tagging page after it does whatever it needs to do with the form fields 如果您想进行任何重定向,则必须在/ tagging页面上执行任何与表单字段有关的操作后再进行重定向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM