我正在使用 php 和 MSSQL 开发 Web 服务。我可以连接 db 并检索值。但是当我使用 json 时,它不会返回任何值。
用于 Web 服务的 ajax 代码是
$.ajax({
url: 'http://209.249.81.138/dev/logintalk.php',
type: 'POST',
data: "username=" + $("#username").val()+"&password=" + $("#password").val(),
dataType: 'json',
success: function(data){
alert(data);
},
error: function(){
alert("failure...");
}
});
}
使用的php代码是
<?php
$server = "server";
$username = "username";
$password = "secret";
$database = "db";
$con = mssql_connect($server, $username, $password) or die("Couldn't connect to SQL Server on $Server");
$users = $_POST['username'];
$passwd = $_POST['password'];
$selected = mssql_select_db($database, $con) or die("Couldn't open database $database");
mssql_query('SET CHARACTER SET utf8');
$query = "SELECT * FROM zNewUsers WHERE memberid = '$users' AND userid = '$passwd'";
$result = mssql_query($query) or die ("Unable to verify user because ");
$row = mssql_fetch_array($result);
$count = mssql_num_rows($result);
if($count == 0){
$data=array(0=>"Incorrect values...");
$value[]=$data[0];
echo json_encode($value);
}
else{
$val[]=$row['SessionID'];
echo json_encode($val);
}
mssql_close($con);
?>