简体   繁体   English

如何通过get来删除url参数,而不会丢失发送PHP,javascript的值?

[英]How to remove a url paramaters via get without lost the values send PHP, javascript?

I've the following template, that render a list o links, each link has a code, and name like a <a name="codigo" class="integrantes" href="#000356">Name of someone<a> 我有以下模板,该模板呈现链接列表,每个链接都有一个代码,并且名称类似于a <a name="codigo" class="integrantes" href="#000356">Name of someone<a>

<div class="panel-group" id="accordion-integrantes">
<div class="panel panel-default">
  <div class="panel-heading">
        <h4 class="panel-title">
          <a data-toggle="collapse" data-parent="#accordion" href="#integrantes>">
            <?php echo $this->titulo; ?>
          </a>
        </h4>
  </div>

  <div id="integrantes" class="panel-collapse collapse in">
      <div class="panel-body">  
        <div class="table-responsive" >
          <table class="table table-hover" id="table-integrantes">
            <?php foreach($this->integrantes as $key => $value ): ?>
            <tr>
              <td>  <a  name="codigo" class="integrantes" code="<?php echo $key; ?> "> <?php echo $value ?> </a></td>  
            </tr>
            <?php endforeach; ?>
          </table>
        </div>
      </div>
  </div>
</div>
</div>

I wanna send a code vía get in the url, so I use the following function on javascript 我想通过网址发送代码,以便在javascript上使用以下功能

$(function(){
 $('.integrantes').bind( 'click',function(){
    var code = $(this).attr( 'code');
    window.location.href = "CVLACController.php?code=" + code; 
 });
});

When I press the link y send a code I and get a url lik http://testdomain.com/CVLACController.php?code=0000292915 当我按链接y时,请发送代码I并获取网址,例如http://testdomain.com/CVLACController.php?code=0000292915

It's fine, but Whe I generete a view with my controller and I use a collapse boostrap , that it use a id-of-div to expand o collapse a div, the problem is that it find the id-of-div like a 这很好,但WHE我generete我控制器的景色,我用一个崩溃的自举 ,它使用一个id-of-div扩大Ø折叠DIV的问题是,它找到id-of-div

http://tesdomain.com/CVLACController.php?code=0000292915#id-of-div http://tesdomain.com/CVLACController.php?code=0000292915#id-of-div

But this wrong, I hope something like 但是这个错,我希望像

http://testdomain.com/CVLACController.php#id-of-div http://testdomain.com/CVLACController.php#id-of-div

Now, I don't know how to remove the url parameters without lost the value of the variable dispatched. 现在,我不知道如何删除url参数而又不会丢失分配的变量的值。 To apply the accrodion boostrap 施加加速助推器

how to send the parameters via post in this case, the right way and work fine the collapse-bostrap ? 在这种情况下,如何通过post发送参数,正确的方法以及折叠崩溃的工作原理

or 要么

how to remove the parameters of the url without lost the values of the variables and work fine the collapse-bostrap ? 如何在不丢失变量值的情况下删除url的参数,并确保折叠程序正常运行

You can use a hidden form and post your code and it won't seen in the url. 您可以使用隐藏的表单并发布您的code而该code不会在url中显示。 Here is an example; 这是一个例子。

<form id="send_code" action="CVLACController.php" type="POST">
    <input type="hidden" name="code" id="code" value=""/>
</form>

you can put any above form anywhere in your page, and in your js; 您可以在页面和js中的任何位置放置以上任何形式的表格;

$(function(){
 $('.integrantes').bind( 'click',function(){
    var code = $(this).attr( 'code');
    $("#code").val(code);
    $("#send_code").submit(); 
 });
});

By doing this, you can post code value to CVLACController.php without any parameter in url. 这样,您可以将代码值发布到CVLACController.php而无需在url中添加任何参数。 And do not forget to get code in CVLACController.php ; 并且不要忘记在CVLACController.php获取code

$code = $_POST["code"];

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

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