user1311784
user1311784

Reputation: 345

detect what page is loaded - ajax

I have this code and some additional JS should be different for each page loaded. How can i do that? Thanks

  function foo(val) {
        $("#paginas").hide("fast").load(('profile' + val + '.php'), function () {

            //pseudo code
            if (page loaded is profile1)
            alert("a");

            if (page loaded is profile2)
            alert("b");

            and so on

        });
    }
    for (var i = 0; i < 8; i++) {
        $('.lista' + i).bind('click', {
            button: i
        }, function (event) {
            foo(event.data.button);
        });
    }

Upvotes: 1

Views: 112

Answers (2)

Jordan
Jordan

Reputation: 32542

You can still access val from within your ajax .load() function, so you could do:

if(val == 'whatever') {
    //do specific thing for "whatever" page
}

Upvotes: 1

SLaks
SLaks

Reputation: 887777

It sounds like you're trying to write if (val === 2)

Upvotes: 4

Related Questions