提交表单之前修改查询字符串 [英] Modifying query string before submitting the form

查看:87
本文介绍了提交表单之前修改查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在提交表单之前修改URL查询字符串.我的表单如下:

I want to modify the URL query string before submitting the form. I'm having a form like below:

 <form name="sampleForm" id="sampleForm" method="get" action="/detailVal" style="display:inline">
            <input type="hidden" name="cId" value="${lId}"/>
            <input type="hidden" name="sId" value="${sId}"/>
            <input type="hidden" name="pKey" value="${pKey}"/>

    onclick="return resetPage('sampleForm',)"><img height="40" width="30" src="/img/next123.png"/></a>

    </form>

    <script type="text/javascript">
    function resetPage(formName) {
         var thisForm = doc
       }    
    </script>

在提交表单之前,我想从/detailVal?cId=1&sId=2&pKey=3更改URL 到/detailVal/cId/1/sId=2/pKey/

Before submitting the form I want to change the URL from /detailVal?cId=1&sId=2&pKey=3 to /detailVal/cId/1/sId=2/pKey/

推荐答案

URL的构建似乎没有任何逻辑,因此仅将字符串与从元素中插入的值一起传递就可以了.重新尝试做,然后阻止表单提交并重定向到该url:

There doesn't seem to be any logic to how the url is built, so just passing the string with the values inserted from the elements is probably what you're trying to do, then just prevent the form from submitting and redirect to that url :

<script type="text/javascript">
    function resetPage(formName) {
         var thisForm = doc
       }    

    $(function() {
        $('#sampleForm').on('submit', function(e) {
            e.preventDefault();
            var cId = $('[name="cId"]').val(),
                sId = $('[name="sId"]').val();

            window.location.href = '/detailval/cid/'+cid+'/sid='+sId+'/pKey/';
        });
    });
</script>

这篇关于提交表单之前修改查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆