WEB How does one use both javascript/jquery AND ajax together?

Discussion in 'OT Technology' started by pantheR, Mar 11, 2010.

  1. pantheR

    pantheR New Member

    Joined:
    Nov 1, 2006
    Messages:
    2,684
    Likes Received:
    0
    Location:
    Washington, DC
    My site content is called from external AJAX files and I need to be able to use jquery in some of these external files.


    in my index.php:
    Code:
    <script type="text/javascript">
    ajax_loadContent('news3','external/home.php');
    </script>
    
    this loads the external 'home.php' without changing the URL.


    however in 'home.php' I have (for example) the html for a jquery script,
    BUT, the jquery code is still in the index.php <head> portion, so
    nothing gets called.

    such as this:
    Code:
            <link href="css/galleria.css" rel="stylesheet" type="text/css" media="screen"> 
                <script type="text/javascript" src="js/jquery.galleria.js"></script> 
                <script type="text/javascript"> 
                jQuery(function($) { $('ul.gallery').galleria(); }); 
                </script>
    So is it possible for the jquery script in 'home.php' to reference the <head> portion of 'index.php'??

    thx
     
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,922
    Likes Received:
    11
    Location:
    Los Angeles
    Can Javascript, jQuery, and Ajax work together? Considering it's all Javascript, yes, it can. But in this implementation, no it cannot. There are much better ways to implement this than the method you're doing.

    I think you should convert your ajax elements to use jQuery.
     
  3. pantheR

    pantheR New Member

    Joined:
    Nov 1, 2006
    Messages:
    2,684
    Likes Received:
    0
    Location:
    Washington, DC
    Can you provide any help on how to do this? All I need is to be able to use a few simple jquery scripts such as lightbox and an image gallery... while still using ajax
     
  4. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,922
    Likes Received:
    11
    Location:
    Los Angeles
    So, you're hacking things together because you don't know what else to do? jQuery has powerful AJAX components that will easily accomplish exactly what you need. Which is why I suggested you convert your AJAX functions to use jQuery.

    The easiest way to accomplish what you're trying to do is present the gallery and script in a single file, then utilize an AJAX load function to insert that file into the element you wish to place it in.

    Or you can dynamically insert the gallery script when home.php is called.

    Or you could design a steady architecture in which your files and javascript functions are usable when needed to avoid problems like this. :dunno:
     
  5. pantheR

    pantheR New Member

    Joined:
    Nov 1, 2006
    Messages:
    2,684
    Likes Received:
    0
    Location:
    Washington, DC
    I want to send you a PM but your inbox is full :|
     

Share This Page