1

When I put var serviceURL = //localhost/services/ it works and shows me the database but when I put it online, the server does not work. Can any one help me? I work on XCode using PhoneGap.

This my 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() .'}}'; } ?> 
3
  • 1
    Where is the .JS file running from? Is it on the server? Is it on your computer? Are you testing from a browser using localhost? Please keep in mind as I said in my answer unless your using JSONP, you cannot use HTML+Javascript from one domain (e.g. localhost or filesystem (file:) ) to access JSON on another server (e.g. panchoslimi.bugs3.com) Commented Apr 19, 2013 at 18:13
  • .JS file running on my computer. no im testing my application using online server (e.g. panchosslimi.bugs3.com/services/getDoctors) so what the problem ? I tell you that when i use localhost it run well and show me the database. but when i run it on online server its not work Commented Apr 19, 2013 at 19:35
  • The problem is if the JS file is not located on the same server as the PHP it doesn't work. Copy the JS and HTML to the webserver, and open that URL. The .js your using needs to be on panchoslimi.bugs3.com as well as the HTML page. Commented Apr 19, 2013 at 19:38

1 Answer 1

0

This seems most likely cross site scripting which is why it is blocked.

Please keep in mind, if your running the site from your computer and trying to access another domain with javascript it will not work unless you are using JSONP (Jason with Padding).

See the following:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.