doumei1955 2013-03-19 07:46
浏览 57
已采纳

Jquery Ajax用于从php mysql获取数据而不刷新页面 - 语法错误[关闭]

I need to get data from mysql database without refreshing the page using jquery ajax. I have a php script which is working fine. However, my JS seems to be having some problem. Here is the jquery script. Also, I am using multiple jquerys on same page like maximage and custom scrollbar.

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); 
});
});

Here is my 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);
?>

Here is my 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>
  • 写回答

3条回答 默认 最新

  • dongzhuan1185 2013-03-19 07:51
    关注

    Use simple ajax as:

      $.ajax({
       url:'getcountry2.php',
       datatype:"application/json",
       type:'get',
       data: 'q='+Country, 
       success:function(data){
          count('#result').append(html); 
       },
       error:function(){
          // code for error
       }
     });
    

    hopw it will help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记