How to use ajax and update img src and call php function? - php

There is a list of checkboxes. User clicks on image of a "unchecked checkbox". Ajax sends request to php script which updates database and echo's new image source of a "checked checkbox". This works fine, and is below:
HTML:
<img src="<?php echo ( $box->complete == 1 ) ? "/images/checkbox-filled.png" : "/images/checkbox-empty.png" ?>" id="checkbox-<?php echo $box->id ?>" />
markBox.js:
$.ajax( {
type: "POST",
url: "/scripts/markBox.php",
data: data,
cache: false,
success: function( imageSource ) {
image.attr( 'src', imageSource );
}
} );
markBox.php:
//Return result
if ( $box->complete == 1 )
echo "/images/checkbox-filled.png";
else
echo "/images/checkbox-empty.png";
exit;
The challenge is that I have php function that is called earlier, above the list of checkboxes, to display to user how boxes are checked and how many are not. I want this box to be called and refresh as the image does. How do I rerun the php function to run again once the ajax comes back?
HTML:
<div class="markBox"><?php echo $results->getCountComplete() ?> Complete</div>
<div class="markBox"><?php echo $results->getCountNotComplete() ?> Incomplete</div>

you don't need ajax at all: (unless you don't want to store your data to a database or a file): I hope this helps:
http://jsfiddle.net/teeEx/
HTML:
<span class="checked"> </span>
<span class="unchecked"> </span>
<span class="unchecked"> </span>
<div id="result"></div>
CSS:
a{
text-decoration: none;
}
span{
display: block;
width: 30px;
height: 30px;
margin: 20px;
}
span.checked{
background: green;
}
span.unchecked{
background: black;
}
JS:
$('a').click(function(){
var a_obj = $(this);
var obj = a_obj.children('span');
if( obj.is('.checked')){
obj.removeClass('checked').addClass('unchecked');
} else {
obj.removeClass('unchecked').addClass('checked');
}
var all = a_obj.parent();
var countChecked = all.find('span.checked').length;
var countunChecked = all.find('span.unchecked').length;
$('#result').html('checked '+countChecked+'; unckecked: '+countunChecked);
});

Related

PHP Ajax Bootrstrap popover placement issue

I am trying to fill my notification popover with AJAX. I have two popovers on the same page. The other popover's content is filled by PHP. The AJAX works fine.
The problem is that the notification popover is being displayed where the other popover is and not below where I am clicking. This problem only occurs when the data content is taken from AJAX. Content produced from PHP or some string works as expected.
Below is the code for the AJAX popover:
$(document).ready(function() {
$('#npop').popover({
template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content" style="padding:0px;overflow-y:auto;max-height:450px;"><p></p></div></div></div>',
html: true,
placement: 'bottom',
title: 'Notifications',
content: function(){
var div_id = "tmp-id-" + $.now();
return details_in_popup(div_id);
}
});
});
function details_in_popup(div_id){
$.ajax({
url: "<?php echo base_url('pull_notify'); ?>",
success: function(response){
$('#'+div_id).html(response);
}
});
return '<div id="'+ div_id +'">Loading...</div>';
}
And this is my HTML element:
<div class="notification-icon navbar-brand">
<span>
<a style="color: #008ae6;font-size:25px;" id="npop" class="glyphicon glyphicon-bell" role="button" data-toggle="popover" ></a></span>
<span id="bad" class="badge badge-notify"></span>
</div>
Ok Solved the issue.
Changed the return div with
return '<div id="'+ div_id +'" style="width: 400px; padding-right: 10px">Loading...</div>';
Apparently the fix was adding a style to the div with a specified width and some css changes in template.
Below is the code
$('#npop').popover({
template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content" style="padding:0px;overflow-y:auto;max-height:450px; width: 400px"><p></p></div></div></div>',
html: true,
placement: 'bottom',
title: 'Notifications',
content: function(){
var div_id = "tmp-id-" + $.now();
return details_in_popup(div_id);
}
});
});
function details_in_popup(div_id){
$.ajax({
url: "<?php echo base_url('pull_notify'); ?>",
success: function(response){
$('#'+div_id).html(response);
}
});
return '<div id="'+ div_id +'" style="width: 400px; padding-right: 10px">Loading...</div>';
}
PS: I am also using the below css,
.popover{
max-width: 600px !important;
max-height: 500px !important;
}
.popover div{
overflow-x: hidden !important;
}

How to send data with AJAX and PHP

I'm trying to implement a commenting box with AJAX and PHP (CodeIgniter framework). Here is the code.
The view (HTML code):
<form id="form" method="post">
<div class="input-group" id="input-group"><!-- input group starts-->
<textarea class="form-control" id="Comment" name="Comment" placeholder="Comment on Scenery..." maxlength="300" cols="70" rows="3" required></textarea>
<input type="hidden" id="uploader_id" value="<?php echo $uploader_id ?>"/>
<input type="hidden" id ="scenery_id" value="<?php echo $scenery_id ?>"/>
<button type="submit" id="submit"class="btn btn-info regibutton" >Post</button>
</div>
</form>
<hr/>
<div class="comment-block">
<?php
if ($comment==NULL){
//if no scenery comment echo disclaimer
echo " <ul style = ' margin-left: 0px;padding-left: 0px;'> <li style = 'list-style: none; background-color: #fff; padding : 5px 5px 5px 10px; margin: 5px 5px 5px 5px'>";
echo " No scenery Comments";
echo "</li>
</ul>";
} else {
foreach ($comment as $row){
// if the comments are availabe echo them
echo " <ul style = ' margin-left: 0px;padding-left: 0px;'> <li style = 'list-style: none; background-color: #fff; padding : 10px 5px 5px 10px; margin: 5px 5px 5px 5px'>";
echo $row->Comment;
echo "<br/>";
echo "<p style='font-size: 11px; color:#333; padding-top: 5px;'>".date(" D d M Y - H:i:s ",strtotime($row->Date_posted))."By - ". $row->Username. " </p>";
echo $row->Date_added;
echo "</li>
</ul>";
}
}
?>
</div>
The AJAX code:
<script>
$(document).ready(function(){
$('#submit').click(function(e){
// remove the error class
$('.input-group').removeClass('has-error');
//remove the previous
$('.help-block').remove();
var Comment = $('#Comment').val();
var scenery_id = $('#scenery_id').val();
var uploader_id = $('#uploader_id').val();
var datastring = 'Comment'+Comment+'&scenery_id'+scenery_id+'&uploader_id'+uploader_id;
$.ajax({
type:'POST',
url: "<?php echo base_url('display_scenery/add_comment')?>",
data: datastring,
datatype: 'json',
cache: 'false',
encode: true
});
.done(function(data) {
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
if(!data.success){
$('#data.errors.input-group'){
$('#iput-group').addClass('has-error');
$('#iput-group').append('<div class= "help">' + data.errors.Comment+'</div>');
} else {
$('#form').append('<div class="alert">'+ data.message+'</div>');
}
)};
.fail(function(data) {
// show any errors
// best to remove for production
console.log(data);
});
}*/
// prevent default action
e.preventDefault();
});
});
</script>
The back end code in CodeIgniter:
public function add_comment(){
if(!$this->session->userdata('logged_in')) {
$data['error'] = 'Signup needed to comment on a scenery';
} else {
$this->load->library('form_validation');
$session_data = $this->session->userdata('logged_in');
$User_id= $session_data['User_id'];
$scenery_id = $_POST['Scenery_id'];
$Comment=$_POST['Comment'];
$this->form_validation->set_rules('Comment', 'Comment', 'trim|required');
if($this->form_validation->run() == FALSE) {
$data['error'] = validation_errors();
} else {
//loads the model image_display then redirects to scenery page
$this-> image_display->add_comment( $scenery_id,$User, $Comment);
$data['Comment']=$this-> image_display->get_comments($scenery_id);
$data['success'] = TRUE;
}
}
echo json_encode($data);
}
I want a system where the user can comment and the comments can be displayed. I'm trying to locate why the code is not working,kindly assist, I'm relatively new to AJAX.
try this :
<script>
$(document).ready(function(){
$('#submit').click(function(e){
// remove the error class
$('.input-group').removeClass('has-error');
//remove the previous
$('.help-block').remove();
var datastring = $("#form").serialize();
$.ajax({
type:'POST',
url: "<?php echo base_url('display_scenery/add_comment')?>",
data: datastring,
datatype: 'json',
cache: 'false',
encode: true
});
.done(function(data)
{
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
if(!data.success){
$('#data.errors.input-group'){
$('#iput-group').addClass('has-error');
$('#iput-group').append('<div class= "help">' + data.errors.Comment+'</div>');
}
else
{
$('#form').append('<div class="alert">'+ data.message+'</div>');
}
)};
.fail(function(data) {
// show any errors
// best to remove for production
console.log(data);
});
}*/
// prevent default action
e.preventDefault();
});
});
</script>

progress bar with $.ajax and php

I'm trying to make a progress bar which works with $.ajax(jquery) and php for a file uploader but I dont know how to assemble it. I know there is a progress bar working with jQuery UI; how ever, it just change while receiving a value. And that's the point. How can I get a dinamic value for the byte uploded?
By the way, this is my code:
fx_file.js
/*This function gets Data from the form and send it to server*/
function fiEnviarDatos2(){
$("form#data").click(function(){
/*Some DOM'S animations*/
});
$("form#data").submit(function(){
var formData = new FormData($(this)[0]);
$.ajax({
url: "PHP/Core/Archivos/upload.php",
type: 'POST',
data: formData,
async: false,
success: function (data) {
/*After actions**/
},
progress:function(data){
alert(data);
},
cache: false,
contentType: false,
processData: false
});
return false;
});`
upload.php
<?php include ("Class_upload.php");
/*Variables*/
$i=0;
$archivos=0;
/*Contains numbers of file sent*/
$archivos=((count($_FILES,1)-6)/5);
/*Contains the user's session name*/
session_start();
$sUsuario=$_SESSION['usuario'];
/*Use the information of each file to create a new class Upload*/
for($i=0;$i<$archivos;$i++){
/*FileSize*/
$tamaArchivo = $_FILES['formUploader']['size'][$i];
/*Filename*/
$nombArchivo = strtolower($_FILES['formUploader']['name'][$i]);
/*Filetemp*/
$tmpArchivo = $_FILES['formUploader']['tmp_name'][$i];
/*It creates class Upload*/
$archivo_subir=new Upload($nombArchivo,$tamaArchivo,$tmpArchivo,$sUsuario);
/*It validates each file and returns a status*/
$estatus=$archivo_subir->enviarData();
/*Returns if file's been uploaded or not*/
$resultFile=$archivo_subir->resultFile($estatus);
echo "<br>";
if($estatus>0){
echo "<div class='resultDeny'>".$resultFile."</div>";
}else{
if($resultFile=="ServerError"){
echo "<div class='resultServer'>".$resultFile."</div>";
}else{
echo "<div class='resultSuccess'>".$resultFile."</div>";
}
}
}
I hope I can found some help from you, guys. I know you all are expert. I'm new working with jquery and php; however , i've seen "their power together" and i want to learn more about them.
Thanks for all.
PDT: Sorry for my english, it's not my mother language. JQ &PHP will be.
Check this page out:
http://www.johnboy.com/php-upload-progress-bar/
http://www.johnboy.com/php-upload-progress-bar/upload_frame.phps
basically
function(data) //return information back from jQuery's get request
{
$('#progress_container').fadeIn(100); //fade in progress bar
$('#progress_bar').width(data +"%"); //set width of progress bar based on the $status value (set at the top of this page)
$('#progress_completed').html(parseInt(data) +"%"); //display the % completed within the progress bar
}
)},500);
after investigating almost all day , I achieved what I wanted.
I found this plugin called JQUERY Form Plugin.
[http://malsup.com/jquery/form/][1]
Maybe some of you have used it. It has almost all the necessary options to built a progressbar and to introduce code before and after submitting the form.
So, check it out. Maybe someone finds it useful
Btw , this is how my code looks like now
accountUser.html
<html>
//...
...//
<style>
form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; padding: 15px }
.progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; margin-top:-200px }
.bar { background-image:url(Imagenes/index/pbar-ani.gif); width:0%; height:20px; border- radius: 3px; }
.percent { position:absolute; display:inline-block; top:3px; left:48%; }
</style>
<script language="javascript" src="Scripts/jquery_min_1.8.js"></script>
<script language="javascript" src="Scripts/fx_file.js"></script>
<script language="javascript" src="Scripts/jquery.form.js"></script>
//...
..//
<form action="#" method="post" enctype="multipart/form-data" id="formu">
<input name="formUploader[]" type="file" multiple id="archivo"/>
<input class="button" type="submit" alt="Upload" value="Subir" id="btn_cargar"/>
</form>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
//...
..//
</html>
fx_file.js
$(document).ready(function() {
// prepare Options Object
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
var options = {
url: "upload.php",
type: 'POST',
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
$(bar).animate({width:percentVal});
percent.html(percentVal);
},
success: function(data){
//After actions
}
};
// bind 'formu' and provide a simple callback function
$('#formu').ajaxForm(options);
});
upload.php
<?php include ("Class_upload.php");
/*Variables*/
$i=0;
$archivos=0;
/*Contains numbers of file sent*/
$archivos=((count($_FILES,1)-6)/5);
/*Contains the user's session name*/
session_start();
$sUsuario=$_SESSION['usuario'];
/*Use the information of each file to create a new class Upload*/
for($i=0;$i<$archivos;$i++){
/*FileSize*/
$tamaArchivo = $_FILES['formUploader']['size'][$i];
/*Filename*/
$nombArchivo = strtolower($_FILES['formUploader']['name'][$i]);
/*Filetemp*/
$tmpArchivo = $_FILES['formUploader']['tmp_name'][$i];
/*It creates class Upload*/
$archivo_subir=new Upload($nombArchivo,$tamaArchivo,$tmpArchivo,$sUsuario);
/*It validates each file and returns a status*/
$estatus=$archivo_subir->enviarData();
/*Returns if file's been uploaded or not*/
$resultFile=$archivo_subir->resultFile($estatus);
echo "<br>";
if($estatus>0){
echo "<div class='resultDeny'>".$resultFile."</div>";
}else{
if($resultFile=="ServerError"){
echo "<div class='resultServer'>".$resultFile."</div>";
}else{
echo "<div class='resultSuccess'>".$resultFile."</div>";
}
}
}//End For
<?php>

Javascript error: Uncaught SyntaxError: Unexpected token }

I am creating a chat for my site. It works fine, but a function isn't working inside of a HTML button. I have 3 files I use for it, and one line isn't working.
Before, I had an issue where I set the Javascript function, create the button, and it would say the function doesn't exist. I fixed that, by putting the function below the buttons.
Each button shows an online member, who is on your friends list.
The error I get in confusing me, as I have no idea how this is being caused.
Error: 'Uncaught SyntaxError: Unexpected token } users.php:3'
(users.php is the page I was on, if I change it that changes to the page name.)
With chrome, I can click on the error, that brings up this: 'window.script1357688207590=1;'
Scripts (sorry for being so long):
Script 1: (main script):
var username = '[error]';
$.ajax({
url: 'bchat.php',
type: 'post',
data: { method: 'method2' },
success: function(data){
username = data;
}
});
$.ajax({
url: 'bchat.php',
type: 'post',
data: { method: 'method1' },
success: function(data){
if(data!='do not show chat'){
function ToggleChat(tof){
if(tof == true){
$('#chatWindow').css('visibility','visible');
}else{
$('#chatWindow').css('visibility','hidden');
}
}
$('body').append('\
<div id=chatWindow style="background:white; visibility
:hidden; position: fixed; bottom: 0; right: 0; margin-top:-30px; width:200px; height:350px;">\
<div style="width:100%; height:100%; border:solid black 1px;">\
<div style="hieght:20px; background:rgb(40,40,40); color:white;">\
'+data+'<span> </span>'+username+'\
<button id=chat_close style="float:right; background:rgba(0,0,0,0); border:none; color:white;">\
Close\
</button>\
</div>\
<div id=chatOnline style="overflow:auto;">\
</div>\
</div>\
</div>\
<div id=chat__window style="background:white; visibility:hidden; position: fixed; bottom: 0; right: 200; margin-top:-30px; margin-left:-400px; width:200px; height:350px;">\
\
</div>\
<div id=chat style="position: fixed; bottom: 0; right: 0;">\
<button id=chat_open style="border:none; padding:5px; color:whiteSmoke; background-image: -ms-linear-gradient(bottom, #4A4A4A 0%, #00070A 100%);background-image: -moz-linear-gradient(bottom, #4A4A4A 0%, #00070A 100%);background-image: -o-linear-gradient(bottom, #4A4A4A 0%, #00070A 100%);background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #4A4A4A), color-stop(1, #00070A));background-image: -webkit-linear-gradient(bottom, #4A4A4A 0%, #00070A 100%);background-image: linear-gradient(to top, #4A4A4A 0%, #00070A 100%); width:200px; height:30px;">\
'+data+' <span> </span>Chat\
</button>\
</div>');
$('#chat_open').click(function() {
ToggleChat(true);
});
$('#chat_close').click(function() {
ToggleChat(false);
});
}
}
});
//
//update online users
//
function updateOnline(){
$.ajax({
url: 'bchat.php',
type: 'post',
data: { method: 'method3' },
success: function(data){
$('#chatOnline').html(data);
}
});
}
updateOnline();
setInterval(updateOnline,5000);
Script 2 (function script):
function chatWith(url,un){
$('#chat__window').html('<div style="width:100%; height:100%; margin-top:-30px; border:solid black 1px;"><div style="hieght:20px; background:rgb(40,40,40); color:white;">'+url+'<span> </span>'+un+'<button id=chat_chatting_close style="float:right; background:rgba(0,0,0,0); border:none; color:white;">Close</button></div><div id=chat_chats style="overflow:auto;"></div></div>');
$('#chat__window').css('visibility','visible');
}
PHP script (bchat.php):
<?php
include_once("./login_manager_php_file.php");
if($username&&$userid){
$method = $_POST['method'];
if($method){
if($method=='method1'){
$url = $images['logged_in'];
$html = "<img src='".$url."' width=7.5 height=7.5/>";
}elseif($method=='method2'){
echo $username;
}elseif($method=='method3'){
$friends_q = mysql_query("SELECT * FROM friends WHERE `with`='$username' OR `friender`='$username'");
$thtml = '';
if($friends_q){
while($friend = mysql_fetch_assoc($friends_q)){
if($friend['with']==$username){
$usern = $friend['friender'];
}else{
$usern = $friend['with'];
}
$url = '';
if(ifLoggedIn($usern)===true){
$url = $images['logged_in'];
}else{
$url = $images['logged_out'];
}
if(ifLoggedIn($usern)===true && $usern != $username){
$on = $url;
$html = "
<button onClick='
chatWith('$url','$usern');
'
style='border:none; background:rgba(0,0,0,0);'><img src='".$url."' width=7.5 height=7.5/>";
$thtml = $thtml.$html.$usern.'</button><br/>';
}
}
}
echo $thtml;
}elseif($method==='method4'){
if($_POST['usrn']){
$url = '';
if(ifLoggedIn($_POST['usrn'])===true){
$url = $images['logged_in'];
}else{
$url = $images['logged_out'];
}
echo "<img src='".$url."' width=7.5 height=7.5/>";
}else{
echo '[error]';
}
}
}
}else{
echo 'do not show chat';
}
?>
Try to change the php to add an id attribute to the button, or class if there is going to be more than one. Also, remove the onclick attribute
<button class="btnChat" ...
Just realized you will need to add in the parameters as well. I would add those to data attributes on the button.
<button class="btnChat" data-url="$url" data-usern="$usern"
You will need to make sure the $url and $usern are escaped properly
then in the script 2 file you can hook up the click event for that button:
$(function(){
$('body').on('click','.btnChat',function(){
chatWith($(this).data('url'),$(this).data('usern'));
});
});

jquery post multiple submit errors

i have a big problem , im trying to build a website around the one page template system so hear is how it works..... a user clicks a link: ..... but the problem is i have more then 100 php generated links on one page that is attached to a listener and for some strange reason, every time a link gets clicked, and a user returns back to the main page it doubles the request....
in other words : a user click links.... go to a page ..... and he see's a ton of links.... the user clicks a link..... go to a page. but if a user goes back the ajax call doubles????
ex. 1 post , ... 2 post ..... 4 post.... 8 post ..... 16 post..... 32 post ...... 64 post.....
im trying to debug with chrome, and it shows how many post to the network(HTTP Request) that are made every time one has been called and it shows how many post being made and its doubling
Html Markup :
<script>
// main menu
$('header a').addClass('lvl1Links');
// classifeds
$('#9090 a').addClass('lvl1Links');
//states - citys - cats ads
$('#selectable a').addClass('lvl1Links');
// re-install link management
$(function(){
$('.lvl1Links').click(function(event) {
event.preventDefault();
$('pload').html('<img src="source/image/lbl.gif">');
var page = $(this).attr('id');
var huh = $('input:hidden').val();
var data = 'pop='+huh+'&page='+page;
$.post('source/php/bots/authorize.php',data,function(data){
$('#pager_master_div').html(data).slideDown();
$('pload').html('');
});
});
});
// speacial style on certain input boxes
$('input').addClass('input');
$('#op').removeClass('input');
$('#sp').removeClass('input');
$('button').button();
//$("#BUser_Home_Wrapper a .lvl1Links").removeClass("lvl1Links");
</script><div id="9090"><ol id="selectable"><li class="ui-state-default">
<div class="contr">Alabama</div><div class="citys">Birmingham<br>Montgomery<br>Mobile<br>Huntsville<br>Tuscaloosa<br><li class="ui-state-default">
<div class="contr">Alaska</div><div class="citys">Anchorage<br>Juneau<br>Fairbanks<br>Sitka<br>Ketchikan<br></ol></div><style>
.contr{
}
.citys{
display:none;
position:absolute;
height:110px;
width:100px;
top:30px;
left:-5%;
right:-5%;
z-index:100;
background:#FFF;
border-radius:5px;
border:5px #0099FF solid;
font-size:10px;
}
.cityz{
display:none;
position:absolute;
height:200;
width:100px;
top:-100px;
left:-5%;
right:-5%;
z-index:100;
background:#FFF;
border-radius:5px;
border:5px #0099FF solid;
font-size:10px;
}
.citys a{
font-size:15px;
}
.cityz a{
font-size:15px;
}
#selectable li a{
font-size:14px;
}
#selectable li city a{
}
#selectable {
list-style-type: none; margin: 0; padding: 0;
}
#selectable li {
margin:5px;
position:relative;
border-radius:10px;
padding: 1px;
float:left;
width: 100px;
height: 25px;
text-align: center;
}
</style>
<script>
$('.ui-state-default').mouseenter(function(e) {
$('.citys', this).slideDown(); // added this
}).mouseleave(function(e) {
$('.citys', this).toggle(); // added this
});
// bttom rows
$('.ui-state-default').mouseenter(function(e) {
$('.cityz', this).slideDown(); // added this
}).mouseleave(function(e) {
$('.cityz', this).toggle(); // added this
});
</script>
<results></results><input type="hidden" id="fortknox" name="fortknox" value="c4ca4238a0b923820dcc509a6f75849b"><results></results><input type="hidden" id="fortknox" name="fortknox" value="c4ca4238a0b923820dcc509a6f75849b">
<script>
$('input').addClass('input');
$('button').button();
// click event for all links
$(function(){
$('.lvl1Links').click(function(event) {
event.preventDefault();
$('pload').html('<img src="source/image/lbl.gif">');
var page = $(this).attr('id');
var huh = $('input:hidden').val();
var data = 'pop='+huh+'&page='+page;
$.post('source/php/bots/authorize.php',data,function(data){
$('#pager_master_div').html(data).slideDown();
$('pload').html('');
});
});
});
</script>
php code:
<?
case 'class':
require('functions/cats.php');
classie($p);
break;
function classie($p){
connect();
$state = explode(':',$p[2]);
$total = count($state);
$s = md5('?').'.class.';
$sid = $state[1];
$state = $state[0];
echo "$state";
echo "<ol id=\"selectable\">";
if(isset($p[3])){
$city = explode(':',$p[3]);
$cid = $city[1];
$city = $city[0];
echo " : $city";
$sqlca = mysql_query("SELECT * FROM `cats` WHERE `cityId`= ".$cid." ");
while($rowsy = mysql_fetch_array($sqlca)){
echo " : ".$rowsy['name']."";
}
}
?>
you can solve your problem using unbind click to prevent double clicking and causing
multiple entry. Take a look my revision about your code on JS below:
$(function(){
$('.lvl1Links').bind(''click,function(event) {
event.preventDefault();
$('pload').html('<img src="source/image/lbl.gif">');
var page = $(this).attr('id');
var huh = $('input:hidden').val();
var data = 'pop='+huh+'&page='+page;
$.post('source/php/bots/authorize.php',data,function(data){
$('#pager_master_div').html(data).slideDown();
$('pload').html('');
});
$(this).unbind(event);
});
});

Categories