JavaScript And JQuery Problem?

hey,

i’m trying to design an admin panel with jquery and javascript

i used the code this in my script.js file which included in the index page

$.ajax({
                            type: "POST",  
            				url: "subindex.php",  
            				data: { action: "show" },
                            success: function(theResponse) {
                                $('#target').html(theResponse);
                            }
                        });
                        return false;

the code works just fine and it includes the output from the subindex.php file in the target div, but the problem is that the javascript files which i’m including in the index file is not applied on the output
and when i include the javascript files with the output again the whole page is like reloading all the time.

so my question is, is there any way to apply the javascript on the output data ??

What does the JavaScript do?

it’s like a style of the page in JQuery like this code

$("#main-nav li ul").hide();
		$("#main-nav li a.current").parent().find("ul").slideToggle("slow");
		
		$("#main-nav li a.nav-top-item").click(
			function () {
				$(this).parent().siblings().find("ul").slideUp("normal");
				$(this).next().slideToggle("normal");
				return false;
			}
		);
		
		$("#main-nav li a.no-submenu").click(
			function () {
				window.location.href=(this.href);
				return false;
			}
		); 

You could try using the .on() function to attach the events instead of .click()

That way any newly added items (such as you’re loading with ajax) will also have them applied:


$('#something').on('click', function() {
    // do your stuff here
});

More info: http://api.jquery.com/on/

Edit>>
Ooh, and you can add more code to the success function of your ajax call to set up the initial states of the elements you’ve just loaded.

thank you but this was not what i’m looking for but of course i’ll use it from now on :slight_smile:

and the problem is solved and the solve is to put the styling codes inside the ajax code like

$.ajax({
type: “POST”,
url: “admin.php”,
data: { action: “show” },
success: function(theResponse) {
$(‘#target’).html(theResponse);

        				// and here goes the styling codes ^^


                        }
                    });
                    return false;

so thank you for inspiring me with the idea :slight_smile:

can you please give me some examples ?

cuz it turned to be unsuccessful to include my js files into the ajax call :frowning: :frowning: it worked well but some other functions stopped and i’m using the ajax call in another js file

Well, like how you did in your previous post, that’s what I mean :wink:

:smiley: :smiley: thank you i thought you meant something else :smiley: :smiley: (How dumb I am :D)

i found another solution is that i make the ajax call inside a function and call this function like


function test() {

//my ajax call

}

go = new test();

and it’s working :smiley: :smiley: thank you once again :slight_smile: :slight_smile:

Cool, glad you got it working!