php called by ajax code
-
Hi, i have a problem.
I created a div that is showed when a user click on a link otherwise is hidden..the div is activated by javascript…
Here is the code:
1) HTML/PHP:
<div id="testo"><a href="#" onclick="visualizza('recapiti'); return false"><strong>Visualizza Recapiti Telefonici</strong></a></div> <div id="recapiti" style="display:none;"> <?php if(get_post_meta( get_the_ID(), 'fiemme_telefono', true ) != '') { ?> <p><strong>Telefono</strong>: <?php echo get_post_meta( get_the_ID(), 'fiemme_telefono', true );?></p> <?php } ?> <?php if(get_post_meta( get_the_ID(), 'fiemme_laboratorio', true ) != '') { ?> <p><strong>Laboratorio</strong>: <?php echo get_post_meta( get_the_ID(), 'fiemme_laboratorio', true );?></p> <?php } ?> <?php if(get_post_meta( get_the_ID(), 'fiemme_cellulare', true ) != '') { ?> <p><strong>Cellulare</strong>: <?php echo get_post_meta( get_the_ID(), 'fiemme_cellulare', true );?></p> <?php } ?> <?php if(get_post_meta( get_the_ID(), 'fiemme_fax', true ) != '') { ?> <p><strong>Fax</strong>: <?php echo get_post_meta( get_the_ID(), 'fiemme_fax', true );?></p> <?php } ?> </div>
2) Javascript:
<script type="text/javascript" language="javascript"> function visualizza(id){ if (document.getElementById){ if(document.getElementById(id).style.display == 'none'){ document.getElementById(id).style.display = 'block'; }else{ document.getElementById(id).style.display = 'none'; } } } </script>
Now i want to insert a function that counts how many click users make on this link..I want to create a php file placed on my wordpress root folder and call it by jquery….is it possible? how can i do it?
Obviously i want to count one click for user session, so as not to increase the counter at every click of the same user in the same session.
I tried with this code:
<script type="text/javascript" language="javascript"> function click_counter() { jQuery.ajax({ type: 'POST', url: 'click_counter.php', data:{action:'call_this'}, success:function(html) { alert(html); } }); } </script>
I’ve placed click_counter.php in public_html folder of wordpress, but it seems not attainable..
Now I have two requests:
1) What parameter i have to set on “url:” in the latest code posted to make accessible the file click_counter.php2) how can I build the code that runs the counter as I described at the beginning of post (click_counter.php code)
Thanks you all and sorry for my bad english ??
- The topic ‘php called by ajax code’ is closed to new replies.