include jquery libray in php file

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
Hercules
New php-forum User
New php-forum User
Posts: 8
Joined: Mon May 29, 2017 4:31 pm

Mon Oct 08, 2018 12:10 pm

Hi friends,

I used <link rel="stylesheet" media="all" href="<?php echo url_for('/stylesheets/public.css'); ?>" />

to refernce the css file in a php file, but I can't seem to get the correct syntax to refernce a jquery library. I used the following code but it doesnt work

<script type="text/javascript" src="<?php echo url_for('http://ajax.googleapis.com/ajax/libs/jq ... ery.min.js'); ?>"</script>

Thanks !

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 753
Joined: Mon Feb 22, 2016 5:52 pm

Mon Oct 08, 2018 2:37 pm

Why are you using a function?

What's wrong with just putting this in your page?

Code: Select all

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
or even:

Code: Select all

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I'm assuming that your url_for function adds http:// to the front of the supplied string, this would make the address "http://http://ajax.googleapis.com/ajax/ ... ery.min.js"

Hercules
New php-forum User
New php-forum User
Posts: 8
Joined: Mon May 29, 2017 4:31 pm

Mon Oct 08, 2018 3:05 pm

Thank You for your Help !!! I thought that because the css file url was enclosed in a php tag that my jquery file reference also needs to be enclosed in a php tag?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 753
Joined: Mon Feb 22, 2016 5:52 pm

Tue Oct 09, 2018 7:43 am

I thought that because the css file url was enclosed in a php tag that my jquery file reference also needs to be enclosed in a php tag?
Neither needs to be output from PHP, and the css does not need to have 'http://' infront of it, in fact it would be better if it didn't unless you are using stylesheets from another web site, the browser if perfectly happy to use a local address:

Code: Select all

<link rel="stylesheet" href="/stylesheets/public.css">
Will do very nicely, and it will save PHP, the browser and server from processing it.

Post Reply