You are viewing limited content. For full access, please sign in.

Question

Question

Calling API from Forms Javascript using JQUERY

asked on February 16, 2018

Good afternoon,

 

We have been looking into adding fucntionality to our Forms that would allow calling an API via JQUERY in a forms Javascript.

 

We have found some outside examples of performing this, below is an example:

 

$(document).ready(function() {
  $('#weatherLocation').click(function() {
    let city = $('#location').val();
    $('#location').val("");
    $.ajax({
      url: `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=[API-KEY-GOES-HERE]`,
      type: 'GET',
      data: {
        format: 'json'
      },
      success: function(response) {
        $('.showHumidity').text(`The humidity in ${city} is ${response.main.humidity}%`);
        $('.showTemp').text(`The temperature in Kelvins is ${response.main.temp}.`);
      },
      error: function() {
        $('#errors').text("There was an error processing your request. Please try again.")
      }
    });
  });
});

 

Has anyone found/done anything different in their forms javascript that differs from what is being portrayed above?

 

Any suggestions would be greatly appreciated.

 

Thanks!

0 0

Replies

replied on February 21, 2018

Hi Charles,

What is your issue with using JQuery ajax function? You could follow JQuery document on how to use it http://api.jquery.com/jquery.ajax/

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.