Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
include php in javascript
Old 09-20-2010, 09:00 AM include php in javascript
Novice Talker

Posts: 8
Trades: 0
hi,

I have .js file and I need include php code in this file

Please help my.
issam-rrr is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-20-2010, 09:12 AM Re: include php in javascript
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
I dont think you can.

I dont think the webserver will execute the php code inside the js .
document,write probably wont work either?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 09-20-2010, 09:12 AM Re: include php in javascript
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
I think you are looking for AJAX. You have a lot of reading to do.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-20-2010, 09:14 AM Re: include php in javascript
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
Unless you're looking to create dynamically generated javascript?

You can create a php file and use header("Content-Type: text/javascript") inside your php file (e.g. javascript.php) to set the mime type, then do <script type="text/javascript" src="javascript.php"></script>
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-22-2010, 04:06 AM Re: include php in javascript
Novice Talker

Posts: 8
Trades: 0
Thank you for your reply
Unfortunately did not succeed
My problem is I have a js file which contains the variables I want to take the values of these variables from the database mysql

What is the best way
Thank you
issam-rrr is offline
Reply With Quote
View Public Profile
 
Old 09-29-2010, 09:27 PM Re: include php in javascript
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Try making it a PHP file, just wrap the JS in <script type="text/javascript"> </script> tags, and pop in your <?php //php stuff ?> code in wherever you want.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 09-30-2010, 04:32 AM Re: include php in javascript
ninom's Avatar
Experienced Talker

Posts: 44
Trades: 0
So, you want to store your JS variables in MySQL or you want to read MySQL variables to use them in JavaScript?

First of all you have to understand the principals of JavaScript and PHP and the Internet. JavaScript is interpreted on the client. PHP on the server, which will then send you the completed HTML output to display. You can not dynamically change what PHP sent you without reloading the page. That's the "problem" of the internet. Luckily there is a technology called AJAX which can load a page directly from javascript which allows you to dynamically change the page without reloading. Whatever you want to do, you need AJAX for it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ninom is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to include php in javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23369 seconds with 12 queries