JSFiddle - React, Tailwind, and code Playground

by Scoobler

HTML

<input type="text" value="ashishnjain" id="searchName" /><br />
<input type="button" value="Get Results" id="searchTwitter" />

JavaScript

function gotresults(data) {
    alert(data.max_id);
}

function showDiv() {
    $('<div />').html("Results received").appendTo('body');
}

function showFailDiv() {
    $('<div />').html("Results <b>NOT</b> received").appendTo('body');
}

function someMoreCode(name) {
    alert('Hello ' + name.query);
}

function searchTwitter(query) {
    var dfr = $.Deferred();
    $.ajax({
        url: "http://DONTsearch.twitter.com/search.json",
        data: {
            q: query
        },
        dataType: 'jsonp',
        success: dfr.resolve,
        error: dfr.reject
    }).then(gotresults).then(showDiv).then(someMoreCode).fail(showFailDiv);
}

// Starting can be done with a click:
$("#searchTwitter").click(function() {
    searchTwitter($("#searchName").val());
});

// OR a static call:
searchTwitter("ashishnjain");