Home understanding a http request and nested function in ajax
Reply: 0

understanding a http request and nested function in ajax

user1275 Published in July 18, 2018, 4:55 am

I am referencing this code to build a twitch viewer app, which I'm having difficulties in understanding:

$(document).ready(function() {

  let usernames = ["user1", "user2", "user3", "user4"];

  usernames.forEach(function(user) {
    let http = "https://api.twitch.tv/kraken/streams/" + user;

    function getAjax(getdata) {
        url: http,
        headers: {
          'Client-ID': 'myclientid'
        success: function(data) {

  1. What does 'headers' do exactly? I looked it up on twitch and couldn't find a detailed description. It doesn't look like it gives/adds anything to my http request. Twitch says the header "securely identify my application." but wasn't sure what that mean. I thought if it works similar to an API key it should be included in the request.

  2. What does the 'getdata' function in this code do? does it simply store the data i receive from the ajax request?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.350734 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO