Zaloguj | Zarejestruj | FAQ
Anonymous

Displaying Ajax on website?

+ Odpowiedz

Posty: 2 Strona 1 z 1


Displaying Ajax on website?

przez traitorv2.0 » Wt cze 06, 2017 7:21 pm

So I'm a software lead on my robotics team and I've created a website (https://ngregrichardson.github.io) and I want to grab our match (competition) data and display in on the website. I got a friend to help me with the javascript code (I don't think I have all of what's necessary but I don't think that will affect this) but I cannot for the life of me figure out how to format/display it on the site. Basically, how do I take data from a javascript file and make it look pretty on the website :P\

Here's the code:
Kod: Zaznacz cały
$.ajax({
    url: 'https://www.thebluealliance.com/api/v3/team/frc4750/event/2017pawch/matches',
    headers: {
        'X-TBA-Auth-Key':'kGJ3EWlMyQx2MQjqcg58Blrwh520rgRjiF1GHhLybmY0RfTVMmErWAJMpVKXBhrd'
    },
    method: 'GET',
    dataType: 'json',
    success: function(data){
      console.log(data);
    }
  });
Avatar użytkownika

traitorv2.0

  • Posty: 1
  • Dołączył(a): Wt cze 06, 2017 7:17 pm

Re: Displaying Ajax on website?

przez HTML.net » Wt cze 06, 2017 7:34 pm

This should get you started

Kod: Zaznacz cały

$.ajax({
        url: 'https://www.thebluealliance.com/api/v3/team/frc4750/event/2017pawch/matches',
        headers: {
            'X-TBA-Auth-Key': 'kGJ3EWlMyQx2MQjqcg58Blrwh520rgRjiF1GHhLybmY0RfTVMmErWAJMpVKXBhrd'
        },
        method: 'GET',
        dataType: 'json',
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                addRow(data[i]);
            }
            console.log(data);
        }
    });

    function addRow(data) {
        var row = document.createElement("DIV");
        var winner = document.createElement("SPAN");
        winner.innerText = data.winning_alliance;

        row.appendChild(winner);
        document.body.appendChild(row);
    }
Avatar użytkownika

HTML.net
Site Admin

  • Posty: 1194
  • Dołączył(a): So wrz 11, 2010 11:24 am
--
Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.


+ Odpowiedz

Strona 1 z 1