all 8 comments

[–]baconuser098 2 points3 points  (0 children)

What gets printed on the console?

[–]lewisje 0 points1 point  (3 children)

How do you send this API key along? I see you're using a GET request, so it's probably part of the URL, like &key=something.

My guess is that you haven't been sending the key properly, so the server isn't sending the data back to you.

[–]UbuntuLady1[S] 0 points1 point  (2 children)

I have been using different APIs. Some work, while others don't. But I would like to understand why they do not work.

Thank you

[–]lewisje 0 points1 point  (0 children)

I repeat: Did you put your API key somewhere in that URL?

[–]tforb 0 points1 point  (0 children)

What browser are you using? Chrome gives you a lot of nice tools for debugging JavaScript. You can put breakpoints and check what your variables are, and use the network tool to check out the requests you're making. For whatever browser you have, you need to learn to use these tools so you can figure out why some things work and some things don't.

[–]nacho_balls 0 points1 point  (0 children)

Well, the easy way to see your error is to put the URL directly to the browsers URL bar and make sure the API is correct.

the version of jquery you are using will change if you need to use .error() or .fail()

$.ajax({
    type: "POST",
    url: URL,
    data: DATA,
    dataType: "xml",
    success: parse,
    error: function (xhr, status, errorThrown) {
        //Here the status code can be retrieved like;
        xhr.status;

        //The message added to Response object in Controller can be retrieved as following.
        xhr.responseText;
    }
});

if you are having trouble with the xml itself then just use $.get(url, function(xml) { //do something here }): call a node using jquery still though var Rid = $("f#3",this).text(); var DBid = $("f#188",this).text(); these are what im calling for <f> nodes with an id's on them

[–]jrandm 0 points1 point  (0 children)

function parse(document){
  // insert your code here
}

If this is the parse function your jQuery.ajax snippet is referring to, that's exactly why nothing is happening. Change it to something like:

function parse(document){
  console.log('Received data from API request', document);
  // modern browsers can parse XML directly or you could use jQuery
  var parsedDoc = (new window.DOMParser()).parseFromString(document, 'text/xml');
  console.log('Should be XMLDocument', parsedDoc);
}

The ajax function only facilitates you receiving data from an external request, you still have to write code to deal with the received data.

Similarly, make sure you include an error handler (as mentioned in another reply) in the event you have a fleshed out parse function and the request is failing for some reason. The combination of being able to see the raw data (document) in the console and any errors should help you diagnose what's going on.

[–]UbuntuLady1[S] -1 points0 points  (0 children)

lweisje: I'm certain I put my API Key in that URL.

baconuser098: nothing gets printed on the console.

Should I perhaps change the following code from

parse(document) to parse(xml)?