Can anyone tell me why my alert(id) isn't firing off? Nada, zilch, zippo
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 >开发者_StackOverflow社区; 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>
Isn't it just .click to bind the event not .onclick?
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.
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()
.
$("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});
});
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">
?
精彩评论