i am working on a Jquery mobile project and want to load a json. The json comes from a .php file. The problem is that it will not load.
My .php file looks like this.
<?php
$query=mysql_query("SELECT * FROM `data`");
while($data=mysql_fetch_assoc($query))
$output['result'] []=$data;
header('Content-Type: application/json', true);
echo json_encode($output);
?>
I tried 2 different methods inside my jquery:
$.ajax({
url: "http://www.example.com/jsonfile.php",
dataType : "json"
}).success(function(data){
$.getJSON('http://www.example.com/jsonfile.php', function(data) {
Here is a little recap. When using a local .json file everything works. But when i call the same file on the server it does not. The error i get is:
The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.
In my .php file i can get rid of this error using: header('Content-Type: application/json; charset=US-utf-8');
Even without the error in my .php both files won't work. (my database is utf8_general_ci)