SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast SmAsH_HaCkEr's Avatar
    Join Date
    Aug 2009
    Location
    Egypt
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    Code:
    $.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 ??
    Welcome To My World

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    What does the JavaScript do?

  3. #3
    SitePoint Enthusiast SmAsH_HaCkEr's Avatar
    Join Date
    Aug 2009
    Location
    Egypt
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's like a style of the page in JQuery like this code

    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;
    			}
    		);
    Welcome To My World

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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:

    Code:
    $('#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.

  5. #5
    SitePoint Enthusiast SmAsH_HaCkEr's Avatar
    Join Date
    Aug 2009
    Location
    Egypt
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you but this was not what i'm looking for but of course i'll use it from now on

    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
    Welcome To My World

  6. #6
    SitePoint Enthusiast SmAsH_HaCkEr's Avatar
    Join Date
    Aug 2009
    Location
    Egypt
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Immerse View Post
    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.
    can you please give me some examples ?

    cuz it turned to be unsuccessful to include my js files into the ajax call it worked well but some other functions stopped and i'm using the ajax call in another js file
    Welcome To My World

  7. #7
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Well, like how you did in your previous post, that's what I mean

  8. #8
    SitePoint Enthusiast SmAsH_HaCkEr's Avatar
    Join Date
    Aug 2009
    Location
    Egypt
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you i thought you meant something else (How dumb I am )

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

    Code:
    function test() {
    
    //my ajax call
    
    }
    
    go = new test();
    and it's working thank you once again
    Welcome To My World

  9. #9
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Cool, glad you got it working!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •