I'm trying to parse a json file within an external php file with ajax from a different server (technically the same provider but I don't think it really matters).
Anyway my code in my wordpress website to create a json file from my database is the following:
<pre>
<?php
global $wpdb;
if(!isset($wpdb))
{
require_once('wp-config.php');
require_once('wp-includes/wp-db.php');
}
$result = $wpdb->get_results ( "SELECT * FROM " . $table_prefix . "some_row" );
print_r(json_encode($result, JSON_UNESCAPED_SLASHES));
?>
</pre>
The url of this file is (example) http://somewebsite.com/phpjson.php.
I'm calling from the other url (example) http://app.someotherwebsite.com in this way:
$(document).ready(function() {
$(function(){
$.ajax({
url: "http://somewebsite.com/phpjson.php",
type: "GET",
dataType: "JSON",
cache: false,
success: function(markers) {
$.each(markers,function(i, val){
//do something
}
});
});
For some reason, I'm not able to call the file probably because of the format of for something else, any clue?