Была попытка сварить некоторые JSONP, чтобы обойти проблемы Cross Domain. Используемый ответ здесь: Basic example of using .ajax() with JSONP?JSONP - Как я его использую?
$.getJSON("http://example.com/something.json?callback=?", function(result){
//response data are now in the result variable
alert(result);
});
Но не получив желаемого результата. Мой код:
JQuery
var url = "http://wplivestats.com/stats/jsonp.php?callback=?";
$.getJSON(url, function(result){
//response data are now in the result variable
console.log(result);
});
PHP
<?php
include('init.php');
$pubid = $_REQUEST['pid'];
date_default_timezone_set ('America/New_York');
$time = date('Y-m-d H:i:s',time()-$polling_minutes*60);
$count = $conn->prepare("select distinct ip from stats where timestamp >= '$time' AND Pubid = '$pubid'");
$count->execute();
$users['users'] = $count->rowCount();
echo "jsonCallback ([";
echo json_encode($users);
echo "])";
?>
Ошибка:
ReferenceError: jsonCallback is not defined
jsonCallback ([{"users":0}])
Где я буду неправильно?
Вы не проходя 'pid', но кажется, что вы ожидаете, и' $ users' не определен – adeneo