在http调用中隐藏参数

时间:2016-02-10 07:31:06

标签: php

我用它来传递一个参数(fullname)。

Prefix Verb   URI Pattern                  Controller#Action
      meetings GET    /meetings(.:format)          meetings#index
               POST   /meetings(.:format)          meetings#create
   new_meeting GET    /meetings/new(.:format)      meetings#new
  edit_meeting GET    /meetings/:id/edit(.:format) meetings#edit
       meeting GET    /meetings/:id(.:format)      meetings#show
               PATCH  /meetings/:id(.:format)      meetings#update
               PUT    /meetings/:id(.:format)      meetings#update
               DELETE /meetings/:id(.:format)      meetings#destroy
      new_user GET    /users/new(.:format)         users#new
         users GET    /users(.:format)             users#index
     main_page GET    /main_page(.:format)         welcome#domain
   new_session GET    /sign_in(.:format)           sessions#new
       signout GET    /sign_out(.:format)          sessions#destroy
      sessions POST   /sessions(.:format)          sessions#create
               GET    /sessions/new(.:format)      sessions#new
  edit_session GET    /sessions/:id/edit(.:format) sessions#edit
       session PATCH  /sessions/:id(.:format)      sessions#update
               PUT    /sessions/:id(.:format)      sessions#update
               DELETE /sessions/:id(.:format)      sessions#destroy
               GET    /sessions/:id(.:format)      welcome#domain
               GET    /users(.:format)             users#index
               POST   /users(.:format)             users#create
               GET    /users/new(.:format)         users#new
     edit_user GET    /users/:id/edit(.:format)    users#edit
          user GET    /users/:id(.:format)         users#show
               PATCH  /users/:id(.:format)         users#update
               PUT    /users/:id(.:format)         users#update
               DELETE /users/:id(.:format)         users#destroy
month_for_user GET    /month_for_user(.:format)    calendar#month_for_user

有没有办法传递参数,使其无法在http URL中看到? 我知道POST。

<script type="text/javascript"> 
 function listbox_update(){
  var fullname = document.getElementById("listboxid").value;
  document.location.href="{$_SERVER["PHP_SELF"]}?fullname="+fullname;}
</script>

我会使用POST,因此该参数不存在于URL中,但我不能,因为我使用javascript作为On Click事件。

$listboxselected = $_POST['listbox'];

On Click事件非常有效。但我不想在网址中查看我的所有变量。

3 个答案:

答案 0 :(得分:3)

如果您只想通过JS执行此操作,那么您可以使用Ajax。

 function listbox_update(){
  var fullname = document.getElementById("listboxid").value;
    $.ajax({
        data: { fullname: fullname },
        url: <?php echo $_SERVER["PHP_SELF"]; ?>,
        type: "POST",
        success: function(msg){
          //some function here
        }
    });
}

答案 1 :(得分:2)

<select>换成<form>,然后在onchange中提交表单。

<form id="form" method="post" action="<?=$_SERVER["PHP_SELF"]?>">
    <select id="listboxid" name="fullname" onChange="listbox_update()">
        <option>here the options</option>
    </select>
</form>

listbox_update

function listbox_update () {
    document.getElementById('form').submit();
}

另一种选择是使用Ajax,但由于您的原始脚本重新加载页面,因此第一种方法遵循这种方式。

答案 2 :(得分:2)

您只有两种解决方案:
1)你必须实现如下的AJAX:

  function listbox_update()
  {
     var fullname = $("#listboxid").val();
     $.ajax({
        data: "fullname="+fullname,
        url: <?php echo $_SERVER["PHP_SELF"]; ?>,
        type: "POST",
        success: function(msg){
          console.log("Message :"+msg);
        }
    });
}

2)或者提交表格。

function listbox_update()
{
  $('#your_form_id').attr('action', <?php echo $_SERVER["PHP_SELF"]; ?>);
  $('#your_form_id').submit();
}