weixin_33674437 2014-04-15 18:43 采纳率: 0%
浏览 57

Ajax HTTP请求GET

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] 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记