Jquery mobile get json from .php file workes locally but not on server -
i working on jquery mobile project , want load json. json comes .php file. problem not load.
my .php file looks this.
<?php $query=mysql_query("select * `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 jquery:
$.ajax({ url: "http://www.example.com/jsonfile.php", datatype : "json" }).success(function(data){ $.getjson('http://www.example.com/jsonfile.php', function(data) {
here little recap. when using local .json file works. when call same file on server not. error is:
the character encoding of plain text document not declared. document render garbled text in browser configurations if document contains characters outside us-ascii range. character encoding of file needs declared in transfer protocol or file needs use byte order mark encoding signature.
in .php file can rid of error using: header('content-type: application/json; charset=us-utf-8');
even without error in .php both files won't work. (my database utf8_general_ci)
a few thing can try:
- hader('content-type: application/json;charset=utf-8', true);
- remove content-type altogether
- call mysql_query("set names 'utf8'") after connection db
Comments
Post a Comment