PDA

View Full Version : Javascript and PHP problem



aljohn03
12 Apr 2010, 02:20 PM
I am working on my site which is utilizing PHP. I build pages as a template, using PHP includes for the header and footer, and testing on my local server. There seems to be some sort of problem with adding javascript to the site. Example - I am trying to add sexyCycle (http://suprb.com/apps/sexyCycle/) to feature content on my index page, but it won't load up. I have tested all my JS files in a plain html file and got sexyCycle working fine.

Is there some sort of common issue here I need to work around? Is javascript just co***icting with PHP on my local server? please help!

coiner
12 Apr 2010, 03:37 PM
JavaScript and PHP do not directly interact so that is not your problem.

If you are using jquery/ajax to dynamically place content into your page and that content contains a script, it will not execute unless you explicitly tell it to.

The way I do this, I would have a predefined function in my main js file (in your case it would be something like "startSexyCycle()") This function would be in a script that is in the dynamically loaded content like so:



<div id="dynamicDiv">
...Content...
<script type="text/javascript">
startSexyCycle();
</script>
...Content...
</div>


Once the content has been received and placed into the page by jquery/ajax, you would do this:



var scripts = document.getElementById("dynamicDiv").getElementsByTagName("script");
for (var i = 0, i < scripts.length; i++)
eval(scripts[i].innerHTML);





If this isn't your problem, I would need to see some example code to figure it out.

aljohn03
12 Apr 2010, 03:57 PM
I wouldn't say im using jquery to place content into the page, I basically just have a unordered list of images, the sexycycle.js is just supposed to make them into a slideshow. I tested in an html file, worked fine, added the same thing to my php based site on my apache server and no go.

The html for the images is like this...

<div class="sexyCycle" id="box4">
<div class="sexyCycle-wrap">
<ul class="sexyCycle-content">

<li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/1.png"></li>
<li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/2.png"></li>
<li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/3.png"></li>
<li><img width="320" height="480" src="http://www.suprb.com/apps/sexyCycle/img/4.png"></li>
</ul>
</div>
</div>

Those obviously are the images. The javascript files are placed in the header, with the core jquery 1.4, jquery.sexycycle, and an jquery.easing, which smooths the transitions.

I also have this code in the header which activates

<script type="text/javascript">


// Initialize Home Feature Slideshow

$(document).ready(function() {
$("#box4").sexyCycle({
speed: 500,
interval: 4000
});
});



</script>

And this tiny bit of CSS:

ul.sexyCycle-content { list-style: none; margin: 0; padding: 0; width: 99999999; position: absolute }
li.sexyCycle-content { margin: 0; padding: 0; }
.sexyCycle { position: relative; overflow: hidden; }
.sexyCycle-wrap { position: relative; width: 99999px; }
.sexyCycle-content { width: 99999; position: absolute; overflow: hidden; }
#box4 {
height:480px;
}

Any ideas?

coiner
13 Apr 2010, 12:03 AM
Well first off that css will not work properly because some of the width attributes just have numbers in them. Add 'px' to the end of any number and see if that fixes it... and on that note, am I right in assuming the 99999px thing is something that the script requires? If not, why not just do 100% or auto?

heidner
15 Feb 2011, 06:08 PM
I am also trying to use sexyCycle within php includes, but having no luck. Any ideas why sexyCycle won't work within a php include?

Edit: I noticed during first attempts of implementation that the css file the sexyCycle creator provides is a little sloppy and has some errors. I have already correct those. The new, pretty CSS file works with my HTML version.

rosstaylor345
28 Mar 2011, 12:08 PM
There is no much use for CSS here because the problem can be solved by a lot of numbers. Try to add px at the end of each number or you can just make it 100 percent.

resdog
29 Mar 2011, 04:55 PM
Do this: take the HTML only version of the page and the php version of the page and look at both source codes (after the php renders). This should give you a clue as to why the php version isn't working. Since php and javascript do not interact directly, maybe there is something in the php file that is rendering incorrectly and thus not allowing the javascript to run.

shanebond789
19 Apr 2011, 05:03 PM
CSS would not be very practical because there are figures to solve the issue through including px at the final of each figure or simply create it 100 percent.

andrewwhite345
10 Sep 2011, 06:23 AM
CSS is not at all useful here as there are different ways to solve the problem. You can try to add PX at the end of every number or just make it 100%.

nakibfdc
10 Sep 2011, 09:08 AM
this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate a lot and never seem to get something done. Versatility is one of the benefits of a custom wedding dress, so you should make the most of it.


Facebook Landing Page (http://www.gimmecreative.com)

darrensmith786
15 Sep 2011, 02:37 AM
Very useful in order to solve the problem here as there is a number that the CSS will look to add a pixel or all numbers at the end there, but then it 100 percent.

harryraya
27 Oct 2011, 02:54 AM
Is there some sort of common issue here I need to work around? http://www.cuinsurance.org/xiaozhu1.jpg
http://www.cuinsurance.org/male2.jpg
http://www.cuinsurance.org/male3.jpg

xuma's
02 Nov 2011, 08:49 AM
Is there some sort of common issue here I need to work around?
http://www.cuinsurance.org/male2.jpg
http://www.cuinsurance.org/male3.jpg

carlhooper123
05 Nov 2011, 04:33 AM
This is really very valuable in order to crack the problem here as there is a quantity that the CSS will air to augment a pixel or all statistics at the finish there, but at that time it is at 100 percent.

jacobmartin456
05 Nov 2011, 05:08 AM
Very useful in order to solve the problem here as there is a number that the CSS will look to add a pixel or all numbers at the end there, but then it 100 percent.

davidmorgan786
12 Dec 2011, 05:38 AM
CSS is not at all useful here as there are different ways to solve the problem. You can try to add PX at the end of every number or just make it 100%.

sambrown
13 Dec 2011, 12:12 AM
Thanks ALJOHN for starting this thread. I now know what to do with my issue about Javascript and PHP. Thanks again!

mdiendd123456
19 Dec 2011, 01:50 AM
Said well, support you


_________________
Schaufensterpuppen (http://www.znl-online.de/index.php?main_page=index&cPath=1)

jonathanganesh
24 Dec 2011, 07:16 PM
very nice discussion this is,

----------------------
Jonathanganesh
Hire a php developer (http://www.cogzidel.com/services/hire-dedicated-professional)

ronju
27 Dec 2011, 05:54 AM
The key to any successful website is knowing your visitors. Site Analytics gives you the valuable, real-time data you need – information you can use to spotlight popular products, target new customers, track offer responses and much more. With over 30 detailed reports, you can find out where your visitors are coming from, what paths they take through your site, even where in the world they live.

http://createaserver.com

johnterry356
12 Jun 2012, 01:41 AM
The things that are on display are all very good and they are great ones too. You are sure look very good in them and they are very much affordable too.

Bre45Web
12 Jun 2012, 02:44 AM
wsa
http://www.anuz.info/xiaowang1.jpg
http://www.anuz.info/xiaowang2.jpg
http://www.anuz.info/xiaowang3.jpg

davianmark
18 Jun 2012, 06:39 AM
The app called as the CSS won’t be much valuable here as there are facts that solve the problem and try totaling PX at the end of every single number.

williamxaviers
20 Jun 2012, 05:23 AM
Java script is very useful coding for creating some best website, Sometimes it create problem when we run this script for PHP. This file is called CSS it is used to develop some related script.

christmas11
25 Jun 2012, 01:12 AM
thanks to share info about this.




Christmas Parties Derbyshire (http://christmas.hospitalityline.co.uk/derbyshire-christmas-parties)

William
19 Nov 2012, 04:25 AM
Very good discussion here. I learn a lot

jiopo
19 Nov 2012, 07:15 AM
ok thanks http://importancetechnology.webs.com/

Phillip
26 Nov 2012, 08:34 PM
JavaScript and PHP do not directly interact so that is not your problem.

If you are using jquery/ajax to dynamically place content into your page and that content contains a script, it will not execute unless you explicitly tell it to.

The way I do this, I would have a predefined function in my main js file (in your case it would be something like "startSexyCycle()") This function would be in a script that is in the dynamically loaded content like so:



<div id="dynamicDiv">
...Content...
<script type="text/javascript">
startSexyCycle();
</script>
...Content...
</div>


Once the content has been received and placed into the page by jquery/ajax, you would do this:



var scripts = document.getElementById("dynamicDiv").getElementsByTagName("script");
for (var i = 0, i < scripts.length; i++)
eval(scripts[i].innerHTML);





.
this is a good way to try to figure this problem out. After reading, I feel I have learned much .

amber java
28 Nov 2012, 03:48 AM
Nice discussion!

CHRISTINE_A
04 Dec 2012, 10:21 PM
Agree! support you, ronju.

ailsa
04 Dec 2012, 10:49 PM
Yes, saie very well.

ihspain
05 Dec 2012, 12:04 AM
There are many situation when we send JSON formatted data in POST method to server side(PHP). But when we try to read that in the conventional way i.e. $_POST, it will show a blank array. If we analyse the content in firebug, we can see that the data is there in POST method, but in the backend it's returning NULL.