Pagina 1 din 1

Script ajax load more cu jQuery & PHP

Scris: Mie Noi 09, 2011
de nutzu123
Are cineva vreun script gen "load more" gen facebook adica rezultatele de pe pagina sa curga in jos doar atunci cand cineva apasa pe buton, ceva gen paginare.Va rog daca un script simplu ceva de genu sa mi.l aratati si mie :?

am incercat http://www.bitsntuts.com/css/twitter-like-load-more-jquery-php dar nu merge :? stie cineva o alta solutie sau ce e gresit in acel script?

Multumesc mult!

Script ajax load more cu jQuery & PHP

Scris: Joi Noi 10, 2011
de trif
salut, in primul rand codul de la link-ul acela are multe greseli (eu cred ca sunt intentionate), cei care pun aceste scripturi nu pun tot codul si exact cum trebuie ci trebuie sa te gandesti cum trebuie sa fie si sa te uiti la pagina lor sursa sa vezi ce au mai bagat in plus.
am dat de cap si la line merge.
acum va explic codul, OK?
SA INCEPEM:
faci un index.php care sa contina asta:

Cod: Selectaţi tot

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WebSpeaks.in</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
*{ margin:0px; padding:0px }
ol.timeline
{
list-style:none
}
ol.timeline li
{
position:relative;
border-bottom:1px #dedede dashed;
padding:8px;
color:#3366FF;
}
ol.timeline li a
{
color:#3366FF;
text-decoration:none;
}
.morebox
{
font-weight:bold;
color:#333333;
text-align:center;
border:solid 1px #333333;
padding:8px;
margin-top:8px;
margin-bottom:8px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
}
.morebox a{ color:#333333; text-decoration:none; color:#3366FF;}
.morebox a:hover{ color:#333333; text-decoration:none}
#container{margin-left:60px; width:480px; border:2px dashed #cccccc; padding:5px; }
.heading{
background-color:#2859AA;
border:1px solid #121649;
color:#FFFFFF;
font-weight:bold;
font-size:14px;
padding:3px;
text-align:center;
font-family:Verdana, Arial, Helvetica, sans-serif;
width:97%;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function()
{
	$('.more_updates').live("click",function()
	{
		var ID = $(this).attr("id");
		if(ID)
		{
			$("#more"+ID).html('<img src="loading.gif" />');
			$.ajax({
				type: "POST",
				url: "loadmore.php",
				data: "lastupd="+ ID,
				cache: false,
				success: function(html)
				{
					$("ol#updates").append(html);
					$("#more"+ID).remove(); // removing old more button
				}
			});
		}
		else
		{
			$(".morebox").html('The End');// no results
		}
		return false;
	});
});
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
</head>
<body>
<div id='container'>
<div class="heading">Facebook/Twitter Like Load More Results</div>
	<?php include "loadonce.php"; ?>
</div>
</body>
</html>
dupaia faci un loadmore.php care sa contina:

Cod: Selectaţi tot

<?php
include("conectare.php");
sleep(2);
if(isset($_POST['lastupd']))
{
    $lastupd=$_POST['lastupd'];
    $lastupd=mysql_real_escape_string($lastupd);
    $result=mysql_query("select * from `test` where `id` < '$lastupd' order by `id` desc limit 3");
    while($row=mysql_fetch_array($result))
    {
        $upd_id=$row['id'];    
        $text=$row['denumire'];
?>
<li>
<?php echo $text; ?>
</li>
<?php
}
?>

<div id="more<?php echo $upd_id; ?>" class="morebox">
<a href="#" id="<?php echo $upd_id; ?>" class="more_updates">more updates</a>
</div>
<?php
}
?>
dupaia faci loadonce.php care sa contina

Cod: Selectaţi tot

    <ol class="timeline" id="updates">
    <?php
        include('conectare.php');
        $sql=mysql_query("select * from `test` ORDER BY `id` DESC LIMIT 3");
        while($row=mysql_fetch_array($sql))
        {
            $upd_id=$row['id'];
            $text=$row['denumire'];
        ?>
        <li>
            <?php echo $text; ?>
        </li>
        <?php } ?>
    </ol>

<div id="more<?php echo $upd_id; ?>" class="morebox">
<a href="#" class="more_updates" id="<?php echo $upd_id; ?>">more updates</a>
</div>
si inca un fisier conectare.php

Cod: Selectaţi tot

<?php
$db = mysql_connect("localhost", "", "") or die("Could not connect.");
if(!$db) 
    die("no db");
if(!mysql_select_db("test",$db))
     die("No database selected.");
if(!get_magic_quotes_gpc())
{
  $_GET = array_map('mysql_real_escape_string', $_GET); 
  $_POST = array_map('mysql_real_escape_string', $_POST); 
  $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
else
{  
   $_GET = array_map('stripslashes', $_GET); 
   $_POST = array_map('stripslashes', $_POST); 
   $_COOKIE = array_map('stripslashes', $_COOKIE);
   $_GET = array_map('mysql_real_escape_string', $_GET); 
   $_POST = array_map('mysql_real_escape_string', $_POST); 
   $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
?>
si un fiser jquery.js care sa contina: ce este in link-ul: http://demos.frnzzz.com/jquery.js
si in final bd care vo dau tot eu:

Cod: Selectaţi tot

CREATE TABLE IF NOT EXISTS `test` (
  `id` int(100) NOT NULL AUTO_INCREMENT,
  `denumire` varchar(150) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=185 ;
numele fisierelor se pot schimba cum doriti voi si css-ul pe care este acolo, DOAR FITI FOARTE ATENTI CE MODIFICATI SI UNDE MODIFICATI.
PRECIZEZ ca la mine MERGE FOARTE BINE. daca intampinati vreo problema postati problema intampinata. cu stima trif

Script ajax load more cu jQuery & PHP

Scris: Joi Noi 10, 2011
de nutzu123
ms mult trif :D merge super scriptul...mi de multumiri!