0

您好,我正在尝试基于我正在处理的 joomla 组件中的两个选择选项使用 ajax 进行 mysql 查询。

我不想发布整个 HTML,所以我缩短了它。我检查了值是否通过 php 传递,但我没有得到任何回报。

所以这是php和js:

<html>
<head>
<!-- load necessary files here -->
</head>
<?php
function firstQuery(){
 if(isset($_POST['adr'])){
  $one = $_POST['adr']; //adr is the name of the first select
  $two = $_POST['toadr']; //toadr is the name of the second select

  $db = JFactory::getDbo();
  $query = $db->getQuery(true);
  $query->select(array('range', 'time', 'cost'));
  $query->from('#__transfer_rang');
  $query->where('from="'.$one.'" AND to="'.$two.'"');
  $db->setQuery($query);
  $results = $db->loadObjectList();

  print_r($results);
  exit;
 }
}

firstQuery();
?>

<body>
<script>
$(function=(){
 $("#click").click(function () {
  $.ajax({
   type: "POST",
   data: $("#myform").serialize(),
   success: function(data){
    $('#test').html(data);
   }
  });
 });
});

</script>

<div id="test">
</div>
<form id="myform" method="post" action=""><!-- form stuff here --></form>
</body>

我错过了什么?

4

0 回答 0