tags:

views:

40

answers:

3

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( function(){ $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

+2  A: 

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();
  });
});
John Hartsock
This is the right answer. What is up with the, "You can accept this answer in 6 minutes" message that appears when I try to accept an answer?
Senica Gonzalez
Oh by the way...how simple. Gosh, sometimes I guess we just make things complicated :)
Senica Gonzalez
+1  A: 

this should do it.

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

});
Patricia
A: 

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.

Gaby