我需要在不使用 jquery ajax 刷新页面的情况下从 mysql 数据库中获取数据。我有一个运行良好的 php 脚本。但是,我的 JS 似乎有一些问题。这是jquery脚本。另外,我在同一页面上使用多个 jquery,例如 maximage 和自定义滚动条。
var count = jQuery.noConflict();
count('#CountryName').on ('change',function(){
var Country = count('#CountryName').val();
count.ajax({
type: 'GET' ,
url: 'getcountry2.php',
data: 'q=',
}).done(function( html ) {
count('#result').append(html);
or
count('#result').html(html);
});
});
这是我的php
<link href="main2.css" rel="stylesheet" type="text/css" />
<link href="country.css" rel="stylesheet" type="text/css" />
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$user = mysql_real_escape_string($user);
$pwd = mysql_real_escape_string($pwd);
mysql_select_db("mahc", $con);
$sql="SELECT * FROM texttesti WHERE Country = '".$q."'";
$result = mysql_query($sql);
echo "<div>";
while($row = mysql_fetch_array($result))
{
echo "<blockquote>". $row['Review'] ."</blockquote>";
echo "<p>" . $row['Name'] . " " . $row['ReasonForPanchakarma']."</p>";
}
echo "</div>";
mysql_close($con);
?>
这是我的 HTML
<p>Select the Fields below to see the testimonials of your choice:</p>
<p> <form name="Country">
<select id="CountryName" onChange="showCountry(this.value)">
<option value="">Select a Country:</option>
<option value="USA">USA</option>
<option value="India">India</option>
<option value="Germany">Germany</option>
<option value="Russia">Russia</option>
</select>
</form>
</p>
<div id="result_data">
<script type="text/javascript" src="country2.js"></script>
</div>
</div>