1

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

3 Answers 3

2

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();
  });
});
Sign up to request clarification or add additional context in comments.

2 Comments

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?
Oh by the way...how simple. Gosh, sometimes I guess we just make things complicated :)
1

this should do it.

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

});

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.