0

この関数pagination($total, $limit, $page)はページ番号 [pg#01 pg#02 pg#03 pg#04 NEXT] を返します。

ページ番号 (例: pg#02) をクリックするとjavascript:showPagination('what_here')、関数から返されたページ番号を含む AJAX 要求がサーバーに送信されますpagination()

どちらの機能も正常に動作します。で JavaScript をテストするとshowPagination('2')、サーバーはこの数値 (2) を取得します。

クリックされた要求されたページ番号をサーバーに送信するための正しい構文は何ですか?

<td><a href="javascript:showPagination('')"><?php echo pagination($total, $limit, $page); ?></a></td>
4

3 に答える 3

0

読んだ後、"This question is actually about the correct syntax of how to send to the server a result from pagination() to showPagination() through Ajax."私はあなたに次のことを提案します:

Javascript :

// save current page to global variable
window.globalPageId = 0;

//the pseudo function 
function showPagination(id) {
  id || ( id = globalPageId );
  var xhr = new xmlHttpRequest();
  xhr.open("GET", "/yourPhpPage.php?pageId="+id, true);
  xhr.send();
  xhr.onreadystatechange = function() {
   if(xhr.readyState == 4 && xhr.status == 200) {
    globalPageId = xhr.responseText; //sure if the result is only id of page;
   }
  }
}

次にhtml:

<td><a href="javascript:showPagination(this.getAttribute('page-id')" page-id="id of page here, from php function">link text here</a></td>

また :

<td><a href="javascript:showPagination()">link text here</a></td>
于 2012-07-22T17:08:46.847 に答える
0

私はこれを試す傾向があります:

<td><a href="javascript:showPagination('<?php echo pagination($total, $limit, $page); ?>')"><?php echo pagination($total, $limit, $page); ?></a></td>

しかし一方で、(同じ構文で)使用する方が便利かもしれません

onclick='showPagination(<?php echo pagination($total, $limit, $page); ?>);'
于 2012-07-15T16:29:50.760 に答える
0

編集:あなたがコメントしたように、私はあなたの質問を誤解したと思います. あなたはただ試すことができます:

<td><a href="javascript:showPagination('<?php echo pagination($total, $limit, $page); ?>');"><?php echo pagination($total, $limit, $page); ?></a></td>

また:

<td><a href="#" onclick="showPagination('<?php echo pagination($total, $limit, $page); ?>');"><?php echo pagination($total, $limit, $page); ?></a></td>
于 2012-07-15T17:18:07.217 に答える