tags:

views:

97

answers:

5

First of all let me say thank you to everyone that offered answers...I have definitely advanced and even on my local machine everything is working perfectly.

However it's not working on the server. I tried a bunch of things such as putting session_start() into the included files but nothing has taken.

Rather than post the code here I've zipped up a few files:

http://nerotic.net/aux/code.zip

and you can see the site at the same URL removing /code.zip

index.php: has the AJAX in it... index_page_content.inc.php: is my file to determine which content gets included backend.php: the PHP to process the AJAX sound-how.php: one of the pages that gets included by index.php

The behavior is weird. It won't echo 'src' where I echo it, however it will display it where I'm echoing 'section'. But as soon as I reload it goes back to echoing 'section' in the exact same place.

Also, in Chrome every couple of links that I click on makes the entire page reload.

So if anyone can tell me what I'm doing wrong :)

Thanks in advance.

ORIGINAL POST

I'm new at PHP and relearning JS so any help would be appreciated.

<script language="JavaScript"
type="text/javascript">

    $(document).ready(function() {

          $("div.tabs").tabs(".images > div", {

                // enable "cross-fading" effect
                effect: 'fade',
                fadeInSpeed: 600,
                fadeOutSpeed: 1000,

                // start from the beginning after the last tab
                rotate: false

              // use the slideshow plugin. It accepts its own> configuration
              }).slideshow({autoplay: false, interval:5000});


          $("a.lnav").onclick(function() {
                    // Get the ID of the link
                    var src = $(this).attr("id");
                    alert(id);

                    // Send Ajax request to backend.php, with src set as "id in> the POST data
                    $.post("/backend.php", {"id": src});
                });

          });  </script>
+5  A: 

you probably meant to do alert(src);, can't see any where in yout code where a variable id has a value assigned to it.

Bablo
Yeah, I didn't notice where id was initialized at all...
xil3
Yes...I'm seeing that now.
nero
+6  A: 

Isn't it just .click to bind the event not .onclick?

Iain
Good spot - would say this is it
Graphain
Sounds like it...I'll give this a shot as well.
nero
+1  A: 

You don't define id for alert(id); - would that throw an error rather than an alert?

Is there an <a> tag with a class of lnav like <a class="lnav">?

Graphain
Sorry, my 1st post here and my 1st day with AJAX and pretty new to PHP as well.Here's a sample link:<a href="index.php?page=soundwhy" id="soundwhy" class="lnav">why</a>
nero
+2  A: 
 $("a.lnav").click(function() {
                // Get the ID of the link
                var src = $(this).attr("id");
                alert(src);

                // Send Ajax request to backend.php, with src set as "id in> the POST data
                $.post("backend.php", {id: src});
            });
Nicolo' Verrini
`onclick` should be changed to `click` , then you want to alert the src var. Then you have another error in the `$.post` it is not `{"id":src}` but `{id:src}`
Nicolo' Verrini
Thank you...I'll try this :)
nero
+4  A: 

If you've pasted your code exactly as you set it up you're calling an non-existent method in jQuery. You mean to be using $('a.lnav').click().

g.d.d.c
Thank you :)I can't believe all the excellent help I've gotten in a short time.
nero