PHP Causing Issues with jQuery?

Discussion in 'PHP' started by BrettOwnz, Mar 3, 2010.

  1. #1
    Hello,

    I don't know if any of you have heard of this before, but when I include my PHP file on the same page where I have a jQuery script running, the jQuery scripts on the page stop working. Once I remove the file again, they work fine. If you have heard of this before or have any idea how I might be able to fix it, let me know!

    Thanks!
     
    BrettOwnz, Mar 3, 2010 IP
  2. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #2
    What does the php file do?

    I could help you easier if you post the link, or pm it to me.
     
    Narrator, Mar 3, 2010 IP
  3. halfdata

    halfdata Active Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Hi. Could you provide example of source code?
     
    halfdata, Mar 3, 2010 IP
  4. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #4
    For sure.

    This is the head of my index.php file, where the jQuery code is called and the jQuery code is located. As you can see, the file that is being included on top (functions.php) is the one causing the problem. The source for that will be below.

    Index.php Header:

    
    <?php include('functions.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    	<title>Kuddle.net</title>
    	
    	<!-- STYLESHEETS -->
    	<link rel="stylesheet" href="style.css" type="text/css" media="screen" title="default" charset="utf-8" />
    	<link rel="stylesheet" type="text/css" href="jquery.lightbox-0.5.css" media="screen" />
    	
    	<!-- JQUERY FILES -->
    	<script type="text/javascript" src="js/jquery.js"></script>  
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js" ></script> 
     	
    	<!-- SCRIPTS SPECIFIC TO THIS PAGE -->
    	<script type="text/javascript" src="js/jquery.tweetable.js"></script>
    	<script type="text/javascript" src="js/jcarousellite.js"></script>
    	<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
    	
    	
    	<script type="text/javascript">
    	$(function() {
    		// LIGHTBOX - Select all links that contains lightbox in the attribute rel
    		$('a[@rel*=lightbox]').lightBox(); 
    	
    	
    	// Client Showcase slider
    	   	$("#client_slider").jCarouselLite({
            	btnNext: ".next",
            	btnPrev: ".prev"
        });
    		
    	//Latest Work Slider
    	$("#latest_work > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
    		
    	// Twitter Feed
     	$('#tweet_feed').tweetable({username: 'peteravey', time: true, limit: 2});
    
    	});
    	</script>
    	
    
    
    	<!--[if IE 6]>
    		
    		<link rel="stylesheet" href="ie6.css" type="text/css" media="screen" title="default" charset="utf-8" />
    		
    		<script type='text/javascript' src="js/ie6_pngfix.js"></script>
    	
    		<script>  
    	  		DD_belatedPNG.fix('*');
    		</script>
    	
    	<![endif]-->
    	
    	<!--[if IE 7]>
    		<link rel="stylesheet" href="ie7.css" type="text/css" media="screen" title="default" charset="utf-8" />
    	<![endif]-->
    	
    </head>
    
    Code (markup):
    Functions.php:

    
    <?php
    
    function create_excerpt($string, $wordsreturned)
    /*  Returns the first $wordsreturned out of $string.  If string
    contains fewer words than $wordsreturned, the entire string
    is returned.
    */
    {
    $retval = $string;    //    Just in case of a problem
     
    $array = explode(" ", $string);
    if (count($array)==$wordsreturned)
    /*  Already short enough, return the whole thing
    */
    {
    $retval = $string;
    }
    else
    /*  Need to chop of some words
    */
    {
    array_splice($array, $wordsreturned);
    $retval = implode(" ", $array);
    }
    return $retval;
    }
    
    ?>
    
    Code (markup):
    Thanks for the help guys!
     
    BrettOwnz, Mar 3, 2010 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    do you recieve any warnings or notices??
     
    bartolay13, Mar 3, 2010 IP
  6. hireme

    hireme Member

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #6
    can you try adding the include line after the doctype declaration?
     
    hireme, Mar 3, 2010 IP
  7. webdevuk

    webdevuk Member

    Messages:
    318
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    43
    #7
    If the PHP file which you are including has Any javascript includes or stylesheets which may interupt or overwrite the previous , this would be the reason.

    The problem you are having is the file you are including ... not PHP itself
     
    webdevuk, Mar 4, 2010 IP
  8. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Could you please try removing the php end statement "?>" in the Functions.php and make sure there are no spaces at the top of your html DOC-TYPE.

    Also I would suggest you to include the functions.php file after the <head> tag to avoid this issue.
     
    HivelocityDD, Mar 4, 2010 IP
  9. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #9
    I have tried that. Doesn't make any difference. I will try out all of the suggestions that you guys are giving...
     
    BrettOwnz, Mar 4, 2010 IP
  10. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #10
    The file I'm including does not include any javascript or stylesheets.. It is simply a php file with one function I use to connect to my database and also create an excerpt for my wordpress DB... Anything else that this might be?

    I am having the same problem on another project I am working on. The file i'm including has the same name, but not much similarity.. Hmm..
     
    BrettOwnz, Mar 4, 2010 IP
  11. hireme

    hireme Member

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #11
    have you tried my suggestion? :)
     
    hireme, Mar 4, 2010 IP
  12. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #12
    I just did. Unfortunately, this solution did not help either. Whenever I remove the include my problem disappears! Annoying....
     
    BrettOwnz, Mar 4, 2010 IP
  13. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Try to include the function.php after "</head>" Pls.

    The information you gave is too few.If my suggest is also cann't help you,you'd better to send the php log or give more information later.
     
    sunlcik, Mar 4, 2010 IP
  14. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #14
    Tried it. Unfortunately the solution did not work.. Thank you for the suggestion though!
     
    BrettOwnz, Mar 5, 2010 IP
  15. prithwirajsaha83

    prithwirajsaha83 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    a lightboxc without javascript
    check here
    knowledge-transfers . com/graphic-design/cool-css-techniques-you-should-know

    remove the spaces for the link
     
    prithwirajsaha83, May 1, 2010 IP