I've got problem, when I click ".page" button the content of news.php script doesn't appear in "#newsdiv". Firebug doesn't says there some errors, when I run news.php in my browser it easily gives me data from MySQL so it's js fault and I can't find where I made mistake, can someone help me?
Just wrote some code:
$(document).ready( function() {
$('a.page').click(function() {
var value = $(this).text();
var result = null;
var scriptURL = "/ajax.executable.files/news.php?page=" + value; //url for ajax
$.ajax({
url: scriptURL,
type: 'get',
dataType: 'html',
async: true,
success: function(data) {
$('#newsdiv').html(data);
}
});
});
});
PHP:
<?php
mysql_connect('xxx', 'xxx', 'xxx');
mysql_select_db('xxx');
mysql_query('SET NAMES \'utf8\'');
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET collation_connection = utf8_polish_ci");
if(isset($_GET['page'])){
$page = mysql_real_escape_string($_GET['page']);
}
else{
$page = 1;
}
$page = $page - 1;
$ile = 2;
$od = $page * $ile;
$sql = "SELECT * FROM xxx LIMIT $od, $ile";
$sql = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($sql)){
?>
<div class="newsholder">
<div class="newsheader">
<h1><?php echo $row['title']; ?></h1>
<h2><?php echo $row['subtitle']; ?></h2>
</div>
<div class="newscontent">
<div class="<?php $result = $id % 2; if($result != 0){ echo("rightsideimg"); } else{ echo("leftsideimg"); } ?>">
<img src="<?php echo $row['image']; ?>" />
</div>
<div class="<?php $result = $id % 2; if($result != 0){ echo("leftsidesontent"); } else{ echo("rightsidecontent"); } ?>">
<?php echo $row['content']; ?>
</div>
<div class="clearfix"></div>
</div>
<div class="newsfooter">
<div class="newsgooterright">
<div class="button">
Czytaj wiecej
</div>
</div>
<div class="newsgooterleft">
<small>napisal <b><?php echo $row['author']; ?></b> dnia 26-11</small>
</div>
</div>
</div>
<?php
}
?>
And php for making buttons
<?php
$offset = ceil($count / $ile);
for($i = 1; $i <= $offset; $i++){
echo("<a class=\"page\" href=\"javascript:void(0);\"><div class=\"page\">" . $i . "</div></a>");
}
?>
All files are placed like:
root/index.php with elements to click
root/ajax.executable.files/news.php with php script
root/jscripts/news.js with js for using news.php
Its all files which script is using