下面的图形按钮没有值,只是一个id。我点击它时试图从数据库中获取一些结果。我必须根据图形按钮结构中的 span 获得结果。
<a class="uib-graphic-button default-graphic-sizing default-image-sizing hover-graphic-button active-graphic-button default-graphic-button default-graphic-text widget uib_w_10 d-margins media-button-text-bottom" data-uib="media/graphic_button" data-ver="0" id="admin">
<img src="images/administrativa.png">
<span class="uib-caption">Admin</span>
</a>
的javascript:
$(document).on("click", "#admin", function(evt)
{
/* your code goes here */
var dataString = "admin=";
var $server = "http://localhost/project";
function SelectAdm(){
$.ajax({
type: "post",
url: $server+"/select.php",
data: dataString,
success: function(result, jqXHR){
var vaga = $.parseJSON(result);
$.each(vaga, function(index, item){
var list_item = '<li class="widget uib_w_17" data-uib="jquery_mobile/listitem" data-ver="0" data-icon="carat-r" id="listitem"><a href="#"><span>'+item.CARGO+'</span></a>';
$("#list").append(list_item);
activate_page("#listpage");
});
},
error: function(jqXHR, status){
alert("not working");
}
});
}
new SelectAdm();
});
php文件
<?php
include_once("conn.php");
if(isset($_POST['admin'])){
$adm = "administrativa";
$sql = $mysqli->query("SELECT * FROM vagas WHERE area = '".$adm."' ");
if($sql->num_rows > 0){
while($row = $sql->fetch_array(MYSQL_BOTH)){
$registro = array(
"AREA" => $row['area'],
"CARGO" => $row['cargo'],
"ATIVIDADES" => $row['atividades'],
"SALARIO_INI" => $row['salario_ini'],
"POS_EXPERIENCIA" => $row['pos_experiencia'],
"BENEFICIOS" => $row['beneficios'],
"HORARIO" => $row['horario'],
"ESCOLARIDADE" => $row['escolaridade'],
"LOCAL" => $row['local'],
"INFOS_ADICIONAIS" => $row['infos_adicionais']
);
$retorno[] = $registro;
}
}
$mysqli->close();
$retorno = json_encode($retorno);
echo $retorno;
}
?>
我发错了吗?当我使用输入时,一切正常,安装数据如下:
var state = $("#state").val();
var city =$("#city").val();
var dataString = "state="+state+"&city="+city+"&submit=";
如果没有投入,它如何运作?