I am trying to figure out how to make this code cleaner by removing what is generic in order to make it more modular for my other button clicks. I was thinking of using window. global function in coffeescript but wanted to get the community's opinion. FYI, thub and test are going to be removed in order not to hardcode. They will come from login in fields.
Code:
$('#button_sandbox').on 'click', ->
$.ajax
type: "GET"
url: start_url + "sandbox/list"
dataType: "json"
crossDomain: true
cache: false
beforeSend: (xhr) ->
console.log 'test'
xhr.setRequestHeader('Authorization', 'Basic ' + btoa("thub" + ":" + "test"));
error: (xhr, ajaxOptions, thrownError) ->
console.dir arguments
console.log("*| Status ", xhr.status)
console.log("*| Error", thrownError)
console.log("*| Ajax", ajaxOptions)
success: (data) ->
console.log("Success", data)
$("#data-box").empty()
$('#data-box').append """<h1>Sandbox Results</h1>"""
for i of data
$('#data-box').append "<br>" + "<li>" + data[i]