Help with json with jquerry

Help with json with jquerry
0

#1

Hello guys please give me a minute of your time. Am working on the random code generator and am stuck.I’ve created my own funny quotes in a json file.But when I use $.getJSON I either get “syntax error”, “not well-formated” or " XMLHttpRequest cannot load" .please help me.I’ve been stuck for days.


#2

Could you provide some code? Are you sure your JSON file is valid? Try pasting it in https://jsonlint.com/ and see if you get any errors.


#3

Hey…thanks for your help.
Can you please review my random quote machine?
I want a honest review.
thanks in advance.


#4

You needed to move these 3 lines:

    $("p").html(quote);
    tweetLink = "https://twitter.com/home/?status=" + quote;
    $(".tweetLink").attr("href", tweetLink);   

inside your getJSON success function like so:

$(document).ready(function(){
  var quote;
  var tweetLink;
  $(".experience").click(function(){
    $.getJSON("https://api.icndb.com/jokes/random?limitTo=[nerdy]",function(data){
      quote=data["value"]["joke"];
      $("p").html(quote);
      tweetLink = "https://twitter.com/home/?status=" + quote;
      $(".tweetLink").attr("href", tweetLink);      
    });
  });
});

Because the getJSON function is asynchronous, those 3 lines of code outside the getJSON success function were running before the data was back from the API.


#5

thanks a lot.
really appreciate it


#6

hey
Csn you help me with this?
I cant see what am doing wrong.
Its just not giving me the longitude and latitude.
Its saying its undefined.


#7

Same type of problem you had in the original post.

navigator.geolocation.getCurrentPosition is asynchronous function so you must put any code dealing with the values retrieved back from it inside the anonymous function (the success). You can also use a second argument (also a function) which is used to execute in the event an error occurs during the API call.

See if you can figure out how to solve your problem now that I have given you this information.


#8

thanks a lot…it worked.
the reply was quick too.
so are all jquerry functions asynchronous functions?


#9

Not all, but those which use callback functions such as .ajax or .getJSON do.

The navigator.geolocation.getCurrentPosition is a pure JavaScript function and is not related to JQuery.


#10

hey…Am finally done with the weather app
Your reviews are highly welcomed.


A simple weather app
#11

One suggestion is to read about the toFixed function to limit the number of decimals displayed in your temperatures. Currently, the Celsius version has two decimals and the Fahrenheit version has 14. Also, you have not met all the required user stories for the project. I do not see a background or icon which shows the current weather condtions (i.e. sunny skies, cloudy skies, rain, snow, etc…).


#12

there’s an icon beside the temperature


#13

Hey… please help me with my wiki viewer.
https://codepen.io/step/pen/qPwWQG
is something wrong with the Json data?


#14

Check the browser’s console (Ctrl+Shft+I in Chrome). You have an error you should research. This is a common error for campers working on the Wikipedia project, so use the search feature in the forum first.


#15

It works great now. Found a useful article on the forum.
And thanks for always responding on time.
I appreciate it a lot.