JSFiddle - React, Tailwind, and code Playground

by Darby Rathbone

HTML

<h2>Borken Chat</h2>

    <input class = "draft"
    type = "text" /> <button class = "send"> Send </button>
 
 
 
 
 
 
    <ul class="messages">
     
    </ul >

JavaScript

Chat.guide.start();
$(document).ready(function () {
    delete Chat.display;
    delete Chat.fetch;
    // delete Chat.Send;
    var messages = $("ul.messages");
    //alert("Good so far!");
    var URL = window.location.href
    var username = URL.substring(URL.indexOf("username") + 9);

    //alert($(".draft").val());


    function Retrieve() {
        $.ajax({
            type: "GET", // Get messages from server
            url: "https://api.parse.com/1/classes/chats",
            dataType: "json", // Sent using JSON.
            success: function (response) {
                //alert(response.results[1].text);
                $(".messages li").remove();
                for (var i = 0; i < 10; i++) {
                    $(".messages").append("<li>" + response.results[i].text + "</li>");
                }
            },
            error: function () {
                alert("Problem!");
            }
        });
    }




    $("button.send").click(function () {

        alert("Button pressed!");
        Send($("draft").val(), username); // Sending TextBox + Name;
    }


    function Send(name, message) { // Send message to server
        $.ajax({
            type: "POST",
            url: "https://api.parse.com/1/classes/chats",
            data: JSON.stringify({
                text: "<b>" + name + "</b>" + ": " + message
            }),
            success: function (response) { // Refresh msg list
                Retrieve();
            },
            error: function () {
                alert("Did not send request!");
            }
        });

    }
    }




    // ShowMessages("Message");

    // console.log(username);
    // console.log(URL.indexOf("username"));
    // console.log(URL.indexOf("username") + 8);
    // console.log(URL.charAt(URL.indexOf("username") + 9));


    // Your JavaScript code will go right here!