Reputation: 4555
I am using this d3 plugin: http://kamisama.github.io/cal-heatmap/ its loading json data from a local url, I usually add this control in PHP to check if the call is a proper AJAX call:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
this checks fails and I was able to backtrace it to the d3.json function.
Can someone explain to me what kind of request is d3.json making?
Thank you very much.
EDIT:
This is the code:
<script type="text/javascript">
var cal = new CalHeatMap();
cal.init(
{
cellSize:15,
range: 12,
domain: "month",
data: '<?php echo $url; ?>',
legendHorizontalPosition: 'center',
legendCellSize: 15
}
);
</script>
$url is the url that returns the json.
Upvotes: 0
Views: 132
Reputation: 6192
First of it's not clear from the documentation how data
is processed. So we can take a quick look at the code (Line 2459 src\cal-heatmap.js)
switch(typeof source) {
case "string":
if (source === "") {
_callback({});
return true;
} else {
switch(this.options.dataType) {
case "json":
d3.json(this.parseURI(source, startDate, endDate), _callback);
break;
When we pass a string rather than an object it checks the extension and uses d3's helper method so should behave just like d3.json()
which in itself is wraps around d3.XHR()
. None of the documentation says it sends HTTP_X_REQUESTED_WITH
. A lot of other frameworks do hence why you see it almost the universal method for detecting a AJAX call but it is not required.
Upvotes: 2