AJAX:调用时不会刷新PHP查询

时间:2016-01-16 07:49:10

标签: php jquery ajax

我有一个页面,当我点击一个链接时,应该重新加载一个表。该脚本工作,并且变量已更新(我已经测试过,请参阅代码),但该表不会使用SQL查询中的新数据重新加载。

网页

<!-- SCRIPT START -->
<script type='text/javascript'>
function getResultat(str) {
if (str == "") {
   document.getElementById("txtHint").innerHTML = "";
    return;
} else { 
    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("txtHint").innerHTML = xmlhttp.responseText;
  }
}
xmlhttp.open("GET","getResultat.php?klasse2="+str,true);
xmlhttp.send();
}
}
</script>
<!-- SCRIPT END -->

 <!-- LINK -->
<a style="cursor:pointer" onclick='javascript:getResultat("KSenior")'> KSenior </a>

 <!-- DATA get inserted here -->
 <div id="txtHint"><?php include("getResultat.php"); ?></div><br>

getResultat.php

<?php
if(isset($_REQUEST['klasse2'])) {
$klasse2=$_REQUEST['klasse2'];
// Used to check if variable updates (for debuging only)
echo $klasse2; 
$klasse2= $_REQUEST['klasse2'];
} else {
$klasse2="MSenior";
// Used to check if variable updates (for debuging only)
echo $klasse2;
}

$query = "SELECT DISTINCT *
FROM resultat 
WHERE resultat.klasse =  '$klasse2'
ORDER BY resultat.plassering ASC ";

// THIS SEND THE QUERY TO A CRUD
$selection= array("plassering", "navn","lagnavn", "tid_liten");  
$records_per_page=5;
$newquery = $crud->paging($query,$records_per_page);
$crud->dataview($newquery, $selection, $records_per_page, $sesong,  $bestetid['tid_ny']);

  ?>

如果需要,我可以发布CRUD,但希望我正在犯一些常见的错误?

当使用按钮调用此页面时,开头的echo会重新加载,而不是查询。

0 个答案:

没有答案