当我输入 var serviceURL =//localhost/services/
时,它可以工作并显示数据库,但是当我将其放在网上时,服务器无法工作。谁能帮我?
我使用 PhoneGap 开发 XCode。
这是我的 list.js getJSON
var serviceURL = "http://panchoslimi.bugs3.com/services/";
var employees;
$('#employeeListPage').bind('pageinit', function(event) {
getEmployeeList();
});
function getEmployeeList() {
$.getJSON(serviceURL + 'getDoctors.php',function(data){
$('#employeeList li').remove();
employees = data.items;
$.each(employees, function(index, employee) {
$('#employeeList').append('<li> <a href="DoctorDetails.html?id=' + employee.id + '">' +
'<h4> Dr. ' + employee.firstName + ' ' + employee.lastName + '</h4>' +
'<p>' + employee.title + '</p>');
});
$('#employeeList').listview('refresh');
});
}
<?php
include 'config.php';
$sql = "SELECT e.id, e.firstName, e.lastName, e.title, e.picture, count(r.id)
reportCount " .
"FROM employee e left join employee r on r.managerId = e.id " .
"GROUP BY e.id ORDER BY e.lastName, e.firstName";
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->query($sql);
$MMC = $stmt->fetchAll(PDO::FETCH_OBJ);
$dbh = null;
echo '{"items":'. json_encode($MMC) .'}';
} catch(PDOException $M) {
echo '{"error":{"text":'. $M->getMessage() .'}}';
}
?>
最佳答案
这似乎很可能是跨站点脚本,这就是它被阻止的原因。
请记住,如果您从计算机运行该网站并尝试使用 javascript 访问另一个域,除非您使用 JSONP(Jason with Padding),否则它将无法工作。
请参阅以下内容:
关于php - 使用 getJSON 连接到在线数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16110935/