0

我正在尝试从具有多个地点名称的列表下拉菜单中传递值。这些名称将使用 AJAX 传递给 php,以用作查询要在 xls 中导出的特定地点表的参数。但是php代码没有被执行。谁能帮我解决这个问题。谢谢

以下是代码:

索引.html

<li><a href="#">Reports by Barangay</a>
<ul>
<li><a href="" id="libertad">Libertad</a></li>
<li><a href="#" id="sanvicente">San Vicente</a></li>
<li><a href="#" id="ampayon">Ampayon</a></li>
<li><a href="#" id="mahogany">Mahogany</a></li>
</ul>
</li>

<script type="text/javascript">// <![CDATA[
$(document).ready(function(){
    $("#libertad").click(function(){

    var libertad=$("#libertad").val();



var postdata={

    'libertad':libertad

};

$.ajax({
        type: "POST",
        url: "export.php",
        data: postdata,
        success: function(msg)
        {
          alert('success');
        }
    });


});
</script>

导出.php

<?php


$value=$_POST['libertad'];


$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "";
$DB_DBName = "places";
$DB_TBLName = $value;


$sql = "Select * from $DB_TBLName";


$Use_Title = 1;

$now_date = DATE('m-d-Y H:i');

$title = "RDI files on $now_date";

$Connect = @MYSQL_CONNECT($DB_Server, $DB_Username, $DB_Password)
 or DIE("Couldn't connect to MySQL:<br>" . MYSQL_ERROR() . "<br>" . MYSQL_ERRNO());
//select database
$Db = @MYSQL_SELECT_DB($DB_DBName, $Connect)
 or DIE("Couldn't select database:<br>" . MYSQL_ERROR(). "<br>" . MYSQL_ERRNO());
//execute query
$result = @MYSQL_QUERY($sql,$Connect)
 or DIE("Couldn't execute query:<br>" . MYSQL_ERROR(). "<br>" . MYSQL_ERRNO());
4

2 回答 2

0

val()用于表单元素,如input,selecttextarea

如果要获取链接中的文本,可以使用text()

var libertad=$("#libertad").text();
于 2013-02-13T15:08:32.857 回答
0

在 js 中ul id='abc'赋予函数.click

于 2013-02-13T15:18:09.963 回答