406 (Not Acceptable) error while trying to retrieve CSV data using d3js - d3.js

I'm trying to retrieve CSV data from a URL using D3js, However I get the following error:
GET http://abc/test.csv 406 (Not Acceptable)
my code looks like:
var chartData = d3.csv("http://abc/test.csv", function(d) {
return {
Date : d.Date,
Department : d.Department,
ProductGroup : d.ProductGroup,
Description : d.Description,
ShippingValue : +d.ShippingValue
};

Related

add geojson from arcgis online API to openlayer map

I am trying to get geojson data (point coordinates of a track) using the arcgis online REST API.
var data = {
};
// sends AJAX request and forwards the returned data to the visualiser
data.requestJSON = function(requestParameters) {
$.ajax({
url: "https://services.arcgis.com/........=*&f=geojson" ,
method: 'GET',
success: function(response) {
visualizer.sendDataToMap(response);
},
error: function(error) {
}
});
};
The geojson data should the be processed in another .js and added to a map.
But I cannot turn the data in a vector.
I found some helpful answers here in the forum, but it still does not work.
var visualizer = {}
//prepare the data for visualisation
visualizer.sendDataToMap = function(jsonData) {
console.log("jsondata",jsonData);
var track = new ol.source.Vector({
features: new ol.format.GeoJSON().readFeatures(jsonData)
});
console.log("track",track);
}
The geojson data from the ajax request shown in the console looks as if the right data is passed.
But turning it into a vector, according to some code line I found here in the forum, does not seem to work. I do not understand the console.log.
Can anyone give a hint how to do that?
The console error message looks like
ol.js:319 Uncaught TypeError: b.R is not a function
at mn.l.Va (ol.js:319)
at Object.visualizer.sendDataToMap (visualizer.js:40)
at Object.success (dataProvider.js:10)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at z (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
Or maybe someone has done the same and could provide an example I could try to follow.
Thanks.

TypeError: Object [object Object] has no method ' '

I am getting the following error when I try to create a customer. I tried downgrading Parse. Currently it is running the latest(2.2.8) version but I tried version 1.4.2 too, and I am still getting the following error. What can be the reason for this "TypeError"?
TypeError: Object [object Object] has no method 'isString'
at request (stripe.js 49:25) at post (stripe.js:117:12) at
Object.module.exports.Customers.create (stripe.js:239:16) at main.js:15:22
Main.js:
//STRIPE
var Stripe = require("stripe")
Stripe.initialize = ("sk_test_XXXXX");
Parse.Cloud.define("saveCustomerId", function(request, response) {
Parse.Cloud.useMasterKey();
Stripe.Customers.create({
card : request.params.token,
email: request.params.email,
description: request.params.description,
}, {
success : function(customer) {
var Usr = request.user;
var newcust = Parse.Object.extend("Customer");
var newUsr = new newcust();
newUsr.set("sCID", customer.id);
newUsr.set("parent", Usr);
var pACL = new Parse.ACL();
pACL.setPublicReadAccess(false);
pACL.setPublicWriteAccess(false);
pACL.setReadAccess(Usr, true);
pACL.setWriteAccess(Usr, true);
newUsr.set("ACL", pACL);
newUsr.save(null, {
success : function(customer) {
response.success("customer saved to parse = " + Usr.get("username"));
},
error : function(customer, error) {
response.error("Ops failed to saved customer id ");
}
});
},
error : function() {
response.error("Fejl");
}
});
});
This looks to be a parse API bug, it should be fixed if you roll-back to Parse 1.3.5. In terminal (on mac) or console (on other platforms) type
parse jssdk 1.5.0
Reported and confirmed bug : https://developers.facebook.com/bugs/1024338347618594/
Did you manage to import the stripe module ?
I fixed that error by creating the Stripe module myself.

how can i parse json data using ajax

I am having this json string how can i print "data" one by one in java script.
please help me.
{"results":[{"data":"zzx"},{"data":"as"},{"data":"gfdg"},{"data":"nbn"},{"data":"an"},{"data":"sa"}]}
I tried below but its not working. i am using ajax to retrieve data from controller in codeigniter.
$.each(data.results, function(k, v) {
$.each(v, function(key, value) {
$('#result_table').append('<br/>' + key + ' : ' + value);
})
})

Listing types=other with javascript API

If i do a nearby search using type other via the URL, my businesses show up.
https://maps.googleapis.com/maps/api/place/nearbysearch/json?&types=other&radius=50000&sensor=false&location=40.805232,-74.464679&key=MY_KEY
But when i do the same search via the javascript API i get ZERO_RESULTS.
geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address' : address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var request = {
location : results[0].geometry.location,
radius : '50000',
"types": ["other"]
};
service = new google.maps.places.PlacesService(dijit.registry.byId(
"map").get('map'));
writeLog("GoogleMap.setupMap().getLocation searching, request="
+ JSON.stringify(request));
service.nearbySearch(request, loadPlaces);
}
});
Output:
GoogleMap.setupMap().getLocation searching, request={"location":{"jb":40.79676670000001,"kb":-74.4815438},"radius":"50000","types":["other"]}
GoogleMap.onLoadPlaces() status ZERO_RESULTS
Is there something else that has to be done to get the javascript api to return the same results as the URL.
Are searches working at all in your JavaScript API? Is it only THIS one that doesn't work - or does in fact ANY search return ZERO_RESULTS?

Zipcode to city/state look-up XML file?

Trying to find an XML file I can use in lieu of a look-up database table until we get our web hosting switched over to the right DB.
Can anyone refer me to an XML file with elements whose children have zipcodes, states, and cities? E.g.:
<zip code="98117">
<state>WA</state>
<city>Seattle</state>
</zip>
Or
<entry>
<zip>98117</zip>
<state>WA</state>
<city>Seattle</city>
</entry>
I'll be using LINQ in C# to query this data.
Check out this one, it provides several different free ones.
https://stackoverflow.com/questions/24471/zip-code-database
There is a free zip code database located at:
http://www.populardata.com
I believe its a .CSV file but you could convert it to a XML file quite easily.
Here is code to do city.state autofill based on a zipcode entered.
<script type="text/javascript">//<![CDATA[
$(function() {
// IMPORTANT: Fill in your client key
var clientKey = "js-9qZHzu2Flc59Eq5rx10JdKERovBlJp3TQ3ApyC4TOa3tA8U7aVRnFwf41RpLgtE7";
var cache = {};
var container = $("#example1");
var errorDiv = container.find("div.text-error");
/** Handle successful response */
function handleResp(data)
{
// Check for error
if (data.error_msg)
errorDiv.text(data.error_msg);
else if ("city" in data)
{
// Set city and state
container.find("input[name='city']").val(data.city);
container.find("input[name='state']").val(data.state);
}
}
// Set up event handlers
container.find("input[name='zipcode']").on("keyup change", function() {
// Get zip code
var zipcode = $(this).val().substring(0, 5);
if (zipcode.length == 5 && /^[0-9]+$/.test(zipcode))
{
// Clear error
errorDiv.empty();
// Check cache
if (zipcode in cache)
{
handleResp(cache[zipcode]);
}
else
{
// Build url
var url = "http://www.zipcodeapi.com/rest/"+clientKey+"/info.json/" + zipcode + "/radians";
// Make AJAX request
$.ajax({
"url": url,
"dataType": "json"
}).done(function(data) {
handleResp(data);
// Store in cache
cache[zipcode] = data;
}).fail(function(data) {
if (data.responseText && (json = $.parseJSON(data.responseText)))
{
// Store in cache
cache[zipcode] = json;
// Check for error
if (json.error_msg)
errorDiv.text(json.error_msg);
}
else
errorDiv.text('Request failed.');
});
}
}
}).trigger("change");
});
//]]>
Here is the API - http://www.zipcodeapi.com/Examples#example1.
You can request the content in XML via To get the data back directly in XML you can use .xml in the format in the request.
https://www.zipcodeapi.com/rest/RbdapNcxbjoCvfCv4N5iwB3L4beZg017bfiB2u9eOxQkMtQQgV9NxdyCoNCENDMZ/info.xml/90210/degrees
Will respond with
<response>
<zip_code>90210</zip_code>
<lat>34.100501</lat>
<lng>-118.414908</lng>
<city>Beverly Hills</city>
<state>CA</state>
<timezone>
<timezone_identifier>America/Los_Angeles</timezone_identifier>
<timezone_abbr>PDT</timezone_abbr>
<utc_offset_sec>-25200</utc_offset_sec>
<is_dst>T</is_dst>
</timezone>
<acceptable_city_names/>
</response>
Api docs are at https://www.zipcodeapi.com/API

Resources