[英]Connect to an online database using getJSON
當我輸入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),否則它將無法正常工作。
請參閱以下內容:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.