我正在尝试使用 php 和 java 脚本显示来自 mysql 的数据。我设法在页面上显示数据,但无法将其发送到脚本。以下是我的文件
script1.js
$(document).ready( function() {
done();
});
function done() {
setTimeout( function() {
updates();
done();
}, 200);
}
function updates() {
$.getJSON("cocktail.php", function(data){
$("ul") .empty ();
$each(data.result, function(){
$("ul").append("<li>Poza: "+this['poza']+"</li> <li>Nume: "+this['nume']+"</li><li>Compozitie: "+this['compozitie']+"</li><br/>");
});
});
}
鸡尾酒.php
<?php include ('includes/header_js.php');?>
<?php include_once ('includes/connection.php');?>
<div class="body_bg">
<h2>Arta Cocktail-urilor</h2>
<div class="clr"> </div>
<?php
$sql = "SELECT * FROM cocktail";
$res = mysql_query($sql);
$result = array ();
while($row = mysql_fetch_array ($res) )
{
array_push($result, array('poza' => $row[1],
'nume' => $row[2],
'compozitie' =>$row[3]));
}
echo json_encode(array("result" => $result));
?>
</div><!--end of body_bg-->
<?php include ('includes/footer.php'); ?>
连接.php
<?php
$connection = mysql_connect('localhost', 'root'. '');
if(!$connection){
die('Nu s-a putut conecta la baza de date.' .mysql_error());
}
$db_select = mysql_select_db('first_class', $connection);
if(!$db_select){
die('Eroare de conexiune'.mysql_error());
}
?>
头文件.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>First Class Cocktail</title>
<link rel="stylesheet" href="stylesheets/style.css" type="text/css" />
</head>
<body>
<table></table>
<script type="text/javascript" src="javascripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="javascripts/script1.js"></script>
<div class="container">
<div class="header">
</div><!--end of logo-->
<div class="menu">
<ul>
<li><a href="index.php" class="active"><span>Acasa </span></a></li>
<li><a href="galerie.php"><span>Galerie</span></a></li>
<li><a href="cocktail.php"><span>Cocktail</span></a></li>
<li><a href="about.php"><span> Despre Noi </span></a></li>
<li><a href="contact.php"><span> Contact </span></a></li>
</ul>
</div><!--end of menu-->
<div class="clr"></div><!--end of clr-->
我哪里失败了???提前感谢您浪费时间阅读本文!谢谢!