0

関数;

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
jQuery(function($){
function detail(dataone) {
      $.ajax({
         url: "detail.php?name=" + dataone,
         cache: false
      }).done(function( html ) {
         $("#detail").append(html);
      }).fail(function(jqXHR, ajaxOptions, thrownError){
      });
   }
});
    </script>

テーブルをループします。

while ($row=mysql_fetch_array($query)) {
 echo "<tr onclick='detail(".$row['column1'].")'>";
  echo '<td scope="row">'.$row['column1'].'</td>
        <td>'.$row['column2'].'</td>
    <td>'.$row['column3'].'</td>

  </tr>'; }

ループの出力例。

<tr onclick="detail(name)">
<td scope="row">name</td>
<td>value</td>
<td>value2</td>
</tr>

そしてhtml;

<div id="detail"></div>

get を使用して name を detail.php に送信し、html 出力を詳細 div に戻したいだけです。この機能が動作しないのはなぜですか? (tr をクリックしても何も起こらず、エラーはありません)

詳細.php

if (isset($_GET['name'])) {
echo $_GET['name'];  }
else echo "Test";

編集

これで機能が変更され、機能しました。

var detail = function(dataone)
{ 
   $.ajax({ url: "detail.php?name=" + dataone, cache: false
   }).done(function( html )
{ 
   $("#detail").append(html);
}).fail(function(jqXHR, ajaxOptions, thrownError){ }
);
}
4

2 に答える 2

0

まず、$。ajaxで使用されるオブジェクトのdataプロパティを使用して、データをオブジェクトリテラルとして渡すことをお勧めします。

data: { name: dataone },
dataType: 'html' //since you are fetching HTML

そして、おそらく今はエラーハンドラーにたどり着くので、エラーを検査するために1つ追加することができます。

//...
}).done(function( html ) {
    $("#detail").append(html);
}).fail(function(jqXHR, ajaxOptions, thrownError){
    //handle error
});

これは

$.ajax({
//...
error: function(jqXHR, ajaxOptions, thrownError){
    //handle error
},
//...

thrownErrorおそらく何が悪かったのかを知るのに十分なことを教えてくれるはずです。

$(function(){

    $('.yourTr').click(function(){

          //add ajax stuff here
    });

});
于 2013-02-20T08:22:31.510 に答える
0

関数にいくつかのエラーがあると思います:

jQuery(function($){
     function detail(dataone) {
         $.ajax({
               url: "detail.php?name=" + dataone,
               cache: false
          }).done(function( html ) {
              $("#detail").append(html);
          }); //<----------------------------------------this is extra
            }).fail(function(jqXHR, ajaxOptions, thrownError){
           });
          });
      }; //<-------------------';'
      //<-------------missing the closing doc ready

代わりに、関数をdetail()外部doc readyまたは単に配置してみてくださいremove the doc ready:

   function detail(dataone) {
      $.ajax({
         url: "detail.php?name=" + dataone,
         cache: false
      }).done(function( html ) {
         $("#detail").append(html);
      }).fail(function(jqXHR, ajaxOptions, thrownError){
      });
   }
于 2013-02-20T08:44:03.560 に答える