-4

I have a div element #profInfo and two buttons #profEdit and #profEditDone. The first AJAX call is working, the second one isn't. Can't seem to pinpoint the problem.

jQuery(
    function() {
        $("#profEdit").click(function() {
            $("#profInfo").load("profile_edit_info.php");
        });
    },
    function() {
        $("#profEditDone").click(function() {
            $("#profInfo").load("profile_info.php");
        });
    }
);
4
  • how is it not working? there is no file profile_info.php ? the propInfo is not updated? Commented Jul 2, 2014 at 11:11
  • $(handler,handler) is not valid syntax. Pseudo ready event accepts only one argument
    – A. Wolff
    Commented Jul 2, 2014 at 11:12
  • @florin There is a profile_info.php. @A what is the correct syntax? So use document.ready?
    – Jeff
    Commented Jul 2, 2014 at 11:13
  • @user3786546 e.g: $(function(){$("#profEdit").click(...); $("#profEditDone").click(...);});
    – A. Wolff
    Commented Jul 2, 2014 at 11:14

1 Answer 1

0

The jQuery function takes one function to execute on the document ready event, not two:

jQuery(
    function() {
        $("#profEdit").click(function() {
            $("#profInfo").load("profile_edit_info.php");
        });
        $("#profEditDone").click(function() {
            $("#profInfo").load("profile_info.php");
        });
    }
);

Chances are it was simply ignoring the second function because it doesn't expect a second function parameter after executing the first one. Note also that if these #profEdit and #profEditDone elements are in any way replaced as a result of these AJAX operations then your click bindings will be lost. If that's also happening you'll want to use .on() instead and bind to a common parent element:

jQuery(
    function() {
        $(document).on("click", "#profEdit", function() {
            $("#profInfo").load("profile_edit_info.php");
        });
        $(document).on("click", "#profEditDone", function() {
            $("#profInfo").load("profile_info.php");
        });
    }
);
2
  • Thank you. Just curious though, why do my questions keep getting downvoted?
    – Jeff
    Commented Jul 2, 2014 at 11:26
  • @user3786546: I don't know, I didn't downvote this one. Don't take it personally though, people vote for all sorts of reasons not all of which I would consider proper reasons.
    – David
    Commented Jul 2, 2014 at 11:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.