开发者

jquery bind .load call with .trigger

开发者 https://www.devze.com 2023-01-07 21:08 出处:网络
I feel like I\'m just searching for the wrong keywords in google and on here.I just can\'t seem to find the right answer to this. Or maybe I have and wasn\'t sure what I was reading.

I feel like I'm just searching for the wrong keywords in google and on here. I just can't seem to find the right answer to this. Or maybe I have and wasn't sure what I was reading.

I'm trying to load a div with data via a .load call. Then later on in my script when I click a button, I want to trigger that load again.

$j("#adminList").bind("load", function("categories.php", { action:"get" }){} ); $j("#button").click( func开发者_开发问答tion(){ $j("#adminList").trigger("load"); });

That's a shortened code, but that gives you an example of what I'm trying to do.

Right now, I get a missing formal parameter error on the function.

Thanks for the help1


Binding to the load event is probably not what you want. Simplify this by making a function that calls $.load() and then call this new function in your click event and anywhere else you need it.

Example

function loadAdminList() {
  $("#adminList").load("categories.php", function (responseText, textStatus, xhr) {
     //Handle/Manipulate the return value here 
  });
}

$(document).ready(function() {
  $("#button").click(function() {
    loadAdminList();
  });
});


this should do it.

$(function(){
    $('#adminList').load("categories.php", {action:'GET'});
    $('#button').click(function(){
        $('#adminList').load("categories.php", {action:'GET'});
    }

});


Use

$j("#button")
         .click( 
                function(){ $j('#adminList').load("categories.php", { action:"get" }); }
               )
         .click();

the first click(..) binds your handler and the second (without params) invokes it the first time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号