0

$.ajax({ type:"GET", url: myurl, dataType:'json', data:'username',

4

2 回答 2

0

您应该提供随附的 HTML。您的表单可能正在提交 POST 变量(推荐),在这种情况下$_GET['username']为空。它适用于$_POST['username']吗?

于 2013-10-03T19:14:31.200 回答
0

我建议你做一些修改,如果它可以工作:

I. 如果您的表单使用 method="POST",则同时使用 $_GET 和 $_POST 变量。

二、对所有用户使用不区分大小写的“All”字符串匹配。

<?php
include("dbconnect.php");
$username = isset($_GET['username']) ? $_GET['username']
  : (isset($_POST['username']) ? $_POST['username'] : '');
if(preg_match("/^all$/i", $username))
{
  $query = "select * from broons order by fname asc";
}
else
{
  $query = "select * from broons where username = '$username' order by fname asc";
}
$link = mysql_query($query);
if (!$link) {
  die($query);
}
$rows = array();
while($r = mysql_fetch_assoc($link)) {
  $rows[] = $r;
}
$json = json_encode($rows);

echo $json;
echo $query;
?>

祝你好运。

添加:

我可能会在上面给出错误的方法。

在调用方 jQuery.ajax(),您的用户名字段似乎没有传递到服务器,请尝试以下操作:

$.ajax({
  type:"GET",
  url: myurl, dataType:'json', data: 'username=JohnDoe2'});
于 2013-10-03T19:05:04.740 回答