これは興味深い問題です。私はホームページがいくつかのタブ付きdiv要素で構成されているWebアプリケーションを持っています。各タブ付きのdiv内では、AJAXを介して異なるページが読み込まれ、スムーズなユーザーインターフェースとワークフローが可能になります。私はLaravelページネーションに問題があります。既定のリダイレクトを防ぐために設計した関数は、意図したとおりに動作しますが、AJAXが読み込まれるたびに、それが追加のonclickイベントを追加するようです。以下は、私が意味するもののスクリーンショットです。 ラージャーページ区切りで、委任されたイベントハンドラにバインドされたAjaxロードボタンが複数回発生します
ネットワークパネルに表示されているように、ページ設定リンクのクリックごとに複数の火災が発生します。数回クリックするだけですべて成功したページが返されますが、これはパフォーマンスを著しく低下させます。なぜこれが起こっているのかについての洞察がありがたいです。
以下は、イベントハンドラとそれが呼び出す関数の両方を割り当てるために使用するJavascriptです。私は既に方法論に.off - >。を使用していることに気づくでしょう。
function myPages(origin,div_tag) //origin is an identifier of where the pagination links live
//div_tag indicates where the resultant page will be output to.
{
mydata={tag: div_tag};
$(origin).off('click','.pagination a',mydata, directPages);
$(origin).on('click','.pagination a',mydata, directPages);
}
//event handles are passed the event always, any additional data included is passed
// as a property (i.e. event.data).
function directPages(e)
{
e.preventDefault();
e.stopPropagation();
var url=$(this).attr('href');
var tag = e.data.tag;
loadComponent(url,tag);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
//The first argument defines the parent element used in
//delegating the event handler to the child elements. The
//second identifies the element into which the resulting
//html code that is return will be rendered.
myPages("div.mysources","#sources");
</script>
おかげで、 ライアン