2017-10-09 14 views
0

私は以下のコードを持っています。このコードは、クエリの人の記録を表示します。POSTメソッドで情報を隠しフォームに送信する方法は?

<tr class='clickable-row' onclick="post('/idsPersonas.php/',{ids: <?php "$lista[id_Persona];" ?>});"> 

と未定義のページへ

を私に送って:私はちょうど私がこの方法をやったid_Persona

をキャッシュ隠しフォームによってポスト機能id_Personaを通じて送り、ページidsPersonas.phpに送信します

これは私のコードです:

  <table id="example" cellspacing="0" width="100%"> 
        <thead class="text-primary"> 
         <tr > 

          <th class="cabezera"><center><h4>Fecha</h4></center></th> 
          <th class="cabezera"><center><h4>Hora</h4></center></th> 
          <th class="cabezera"><center><h4>Nombre</h4></center></th> 

         </tr> 
        </thead> 

         <?php 
          if(count($listado)> 0){ 
           foreach($listado as $lista) 
          { 
          $cuenta++;    
         ?> 
        <tbody> 

         <tr class='clickable-row' onclick="post('/idsPersonas.php/',{ids: <?php "$lista[id_Persona];" ?>});"> 

          <td><?php printf("%s",$lista["Fecha"]); ?></td> 
          <td><?php printf("%s",$lista["Hora"]); ?></td> 
          <td><?php printf("%s",$lista["Nombre"]); ?></td> 

         </tr> 
         <?php  
          } 
           }else { 
         ?> 
         <h3> No hay </h3> 
         <?php 
          }//fin else 
          //printf($cuenta_eventos); 
         ?> 
        </tbody> 
       </table> 

JS:

function post(path, params, method) { 
    method = method || "post"; // Set method to post by default if not specified. 
    console.log(method); 

// The rest of this code assumes you are not using a library. 
// It can be made less wordy if you use one. 
var form = document.createElement("form"); 
form.setAttribute("method", method); 
form.setAttribute("action", path); 

for(var key in params) { 
    if(params.hasOwnProperty(key)) { 
     var hiddenField = document.createElement("input"); 
     hiddenField.setAttribute("type", "hidden"); 
     hiddenField.setAttribute("name", key); 
     hiddenField.setAttribute("value", params[key]); 

     form.appendChild(hiddenField); 
    } 
} 

document.body.appendChild(form); 
form.submit(); 
} 
+0

'ポスト( '/ idsPersonas.php /'、' "/idsPersonas.php/" は見つけることができないため、2番目の '/' –

+0

は、未定義のページに送る削除。最後のスラッシュはPatrick Qが示唆しています。idsPersonas.phpがあなたのウェブパスのルートにない場合でも、最初のスラッシュを削除する必要があります。基本的に、スラッシュはエスケープする必要はありません....あなたのパスにスラッシュが必要ですか? ? –

+0

@NawedKhanスラッシュを削除しても未定義の問題があり、コンソールログに_uncaught構文エラー予期しないトークンが表示される_ – Houdini

答えて

0

引用符を間違った場所に配置します。 それは次のように読んでください:

{ids: '<?php echo $lista['id_Persona']; ?>'});"> 
関連する問題