我已经完成了我的php和jquery代码以从mysql服务器获取数据并发送此数据以显示该内容。
这是代码
newsletter_mainframe.php
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'user', 'pwd') or die(mysql_error());
$db = mysql_select_db('dbname', $con) or die(mysql_error());
$SQL = "SELECT * FROM tablename";
if(array_key_exists('rowcount', $_GET)) {
$query = mysql_query("select count(*) as total FROM paperboy");
$result = mysql_fetch_array($query);
$json = array('rowCount' => $result); // can add more data here
return json_encode($json);
}
?>
<link rel="stylesheet" type="text/css" href="css/paperboy.css" />
<div id="rss_cabecera">
canal de noticias
</div>
<script type="text/javascript">
function MuestraNoticia(str)
{
if (str=="")
{
document.getElementById("rss_rcpt").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("rss_rcpt").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","auth/peticion_noticia.php?page="+str,true);
xmlhttp.send();
}
$.getJSON('newsletter_mainframe.php?rowcount', function(data) {
var jsonData = $.parseJSON(data);
var ntop = jsonData.rowCount * 250;
$('#footer').css('top', ntop);
});
MuestraNoticia(1);
</script>
<div id="rss_rcpt">
</div>
AUTH / peticion_noticia.php
<?php
$event=$_GET["page"];
if($page == 1){
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'rsskill', '14789632qwerty') or die(mysql_error());
$db = mysql_select_db('newsletter', $con) or die(mysql_error());
$SQL = "SELECT * FROM paperboy";
$result = mysql_query($SQL);
echo "<style>.PaperPage {position:relative; left:0px; top:0px; width:920px; font-family: 'Ubuntu', sans-serif; font-size: 12px; color:green;}</style>";
echo "<style>.PaperCabPage {padding-left:5px; height:30px; border:1px solid #99cc33; border-radius:10px; font-family: 'Ubuntu', sans-serif; font-size: 14px; background-color:#99cc33; color:#404040; font-weight:bold}</style>";
echo "<style>.PaperFechaData:{background-color:#99cc33; color:white; font-family: 'Ubuntu', sans-serif; font-size: 14px; border:1px solid #99cc33; border-radius:10px}</style>";
echo "<style>.PaperTitData {padding-left:10px; height:30px; border:1px solid white; border-radius:10px; font-family: 'Ubuntu', sans-serif; font-size: 14px; font-weight:bold; text-transform:uppercase; background-color:#99cc33; color:#404040}</style>";
echo "<style>.PaperCabData {padding-left:5px; height:60px; border:0 none; font-family: 'Ubuntu', sans-serif; font-size:14px; font-weight:normal; text-transform:uppercase; text-align:justify; background-color:white; color:#404040}</style>";
echo "<style>.PaperImgData {text-align:center; vertical-align:center; height:230px; width:240px; border:2px solid #99cc33; border-radius:10px; font-family: 'Ubuntu', sans-serif; font-size: 14px; background-color:white; color:#404040}</style>";
echo "<style>.PaperTxtData {vertical-align:top; padding: 5px 5px 5px 5px; height:230px; border:2px solid #99cc33; border-radius:10px; font-family: 'Ubuntu', sans-serif; font-size: 12px; text-align: justify; background-color:white; color:#404040}</style>";
echo "<table class='PaperPage'>";
echo "<tr>";
$GLOBALS['normalizeChars'] = array(
'Á'=>'Á', 'É'=>'É', 'Í'=>'Í', 'Ó'=>'Ó', 'Ú'=>'Ú', 'Ñ'=>'Ñ',
'á'=>'á', 'é'=>'é', 'í'=>'í', 'ó'=>'ó', 'ú'=>'ú', 'ñ'=>'ñ'
);
function arregla($toClean){
return strtr($toClean, $GLOBALS['normalizeChars']);
}
while ($row = mysql_fetch_array($result)) {
arregla($row['contenido']);
arregla($row['cabecera']);
echo "<td colspan='2' class='PaperTitData' style='background: url(http://www.server.com/img/background.png) repeat-x top; width:910px'>" .$row['titulo']. "</td>";
echo "</tr><tr>";
echo "<td colspan='2' class='PaperCabData' style='width:920px'>" .$row['cabecera']. "</td>";
echo "</tr><tr>";
echo "<td class='PaperImgData' style='background: url(".$row['img'].") no-repeat center; width:240px'> </td>";
echo "<td class='PaperTxtData' style='background: url(http://www.server.com/img/background.png) repeat-x top; width:650px'>" .$row['fecha']. "<br><br>" .$row['contenido']. "</td>";
echo "</tr>";
echo "<tr><td colspan='2'></td></tr>";
echo "<tr><td colspan='2' style='border: 0px none'><br><br></td></tr>";
}
echo "</table>";
mysql_close($con);
} else {
die();
}
?>
CONSOLE LOG RETURN:jsonData为null。 这段代码直到今天都没问题,但现在又返回了这个错误。