0

I'm working on a project where I have to make a jQuery call to LSD Finder. For clarification, in this case, LSD is not the drug: it's Land Sub Divisions. Canada is split into hundreds if not thousands of pieces of land and they all have a number, say: 14-22-25-02-W5. It's okay that that doesn't mean anything to you, there's an API for that.

But for some stupid reason, I cannot get that API to work. My jQuery AJAX query is simple:

//the variable 'value' comes from an input, and is correct
var url = "https://www.lsdfinder.com/api/v1/SECRETKEY/lsd/"+value;
$.ajax({
 url: url,
dataType: 'json',
success: function(json) {
 alert('anything?');
},
 error: function(e) {
 alert('nothing');
}
});

It doesn't seem to matter if I do dataType json or jsonp, I keep getting 'nothing'. I tried getting a more intelligent error, like an Response Text or something by modifiying the error callback to read the following:

error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.toSource());
alert(textStatus.toSource());
alert(errorThrown.toSource());
}

And my responses were, including the original error function:

nothing
//deep breath, and....
({readyState:0, setRequestHeader:(function (a,b){if(!v){var c=a.toLowerCase();a=u[c]=u[c]||a,t[a]=b}return this}), getAllResponseHeaders:(function (){return v===2?e:null}), getResponseHeader:(function (a){var c;if(v===2){if(!f){f={};while(c=cl.exec(e))f[c[1].toLowerCase()]=c[2]}c=f[a.toLowerCase()]}return c===b?null:c}), overrideMimeType:(function (a){return v||(l.mimeType=a),this}), abort:(function (a){return a=a||w,g&&g.abort(a),y(0,a),this}), state:(function (){return c}), always:(function (){return e.done(arguments).fail(arguments),this}), then:(function (){var a=arguments;return p.Deferred(function(c){p.each(b,function(b,d){var f=d[0],g=a[b];e[d[1]](p.isFunction(g)?function(){var a=g.apply(this,arguments);a&&p.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f+"With"](this===e?c:this,[a])}:c[f])}),a=null}).promise()}), promise:(function (a){return typeof a=="object"?p.extend(a,d):d}), pipe:(function (){var a=arguments;return p.Deferred(function(c){p.each(b,function(b,d){var f=d[0],g=a[b];e[d[1]](p.isFunction(g)?function(){var a=g.apply(this,arguments);a&&p.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f+"With"](this===e?c:this,[a])}:c[f])}),a=null}).promise()}), done:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), fail:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), progress:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), success:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), error:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), complete:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), statusCode:(function (a){if(a){var b;if(v<2)for(b in a)r[b]=[r[b],a[b]];else b=a[x.status],x.always(b)}return this}), responseText:"", status:0, statusText:"error"})
new String("error")
new String("")

So, as you can see, it's failing 100%, and I have no idea why. I thought perhaps that the JSON array I'm getting back is incorrect or broken, so I got it and ran it through a JSONLint and it said it was valid. Just so you can see it, it's:

[
{
 "query": "14-22-25-02-W5",
 "response": {
 "status": "ok",
 "err": [],
 "lat": 51.152259,
 "lng": -114.202199,
 "country": "Canada",
 "province": "AB",
 "city": "Calgary",
 "street": "49 Royal Vista Drive NW",
 "street_prox": 78,
 "address": "49 Royal Vista Drive NW, Calgary, AB",
 "lsd": "14-22-25-2 W5",
 "lsd_border": [
 [
 51.150459,
 -114.199327
 ],
 [
 51.150447,
 -114.205067
 ],
 [
 51.154059,
 -114.205071
 ],
 [
 51.154072,
 -114.199332
 ],
 [
 51.150459,
 -114.199327
 ]
 ],
 "uwi": "",
 "nts": "",
 "nts_border": [],
 "utm": "11S 695661E 15670479N",
 "utm_v": "Zone 11, 695661 meters easting, 15670479 meters northing (Southern Hemisphere)"
 }
}
]

What I want to do, ultimately, is to get this query to work and then get the latitude and longitude and made a point on a dynamic Google Map with it. But first, I need to get the query to work with me. I think the problem may lay in the fact that I'm ajaxing to a https address, but it's 3:30am and I can't think straight, so I hope somebody out there has an idea.

Thank you.

asked Oct 29, 2013 at 9:30
3
  • 1
    Can you give an example of what the "value" can be? Never mind, I just noticed that you didn't want to expose your key. What happens if you paste the complete url in your browser? Commented Oct 29, 2013 at 9:32
  • An example of value is "14-22-25-02-W5". I would share the key but I had to pay for it :( If I paste the complete url into my browser I get the above json array, which does validate. Commented Oct 29, 2013 at 9:46
  • What is your serverside language? Commented Oct 29, 2013 at 10:01

2 Answers 2

2

jQuery Ajax doesn't support cross-domain queries by default. Try adding crossDomain: true to your request options.

answered Oct 29, 2013 at 9:37
Sign up to request clarification or add additional context in comments.

2 Comments

+1 The server will also need to provide JSONP support for JSONP to work.
I ended up doing a query to a local file, and that file did a cURL to the API and got the result. It was an issue with the crossDomain. I never did figure it out, but I got it to work another way. But thanks for your answer :)
0

It seems that you are accessing something which is not on your server.

You need to use COARSE.

answered Oct 29, 2013 at 9:35

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.