Module: Ajax

Defined in:
lib/red_query/ajax.rb

Class Method Summary collapse

Class Method Details

.request(options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/red_query/ajax.rb', line 2

def self.request(options)
  options[:data] = options[:data] || {}
  params = options[:data].to_query_string
  success_callback = Proc.new { |text| options[:success].call(String.new(text)) }
  error_callback = Proc.new { |msg| options[:problem].call(String.new(msg)) }
  
  `jQuery.ajax({
    url:#{options[:url]}.__value__, 
    type:#{options[:method]}.__value__, 
    data:#{params}.__value__,
    success: function(msg) { return #{success_callback}.m$call(msg); },
    error: function(xhr,msg) { return #{error_callback}.m$call(msg); }
  })`
end

.requestJSON(options) ⇒ Object



17
18
19
20
21
22
# File 'lib/red_query/ajax.rb', line 17

def self.requestJSON(options)
  orig_success = options[:success]
  options[:success] = Proc.new { |text| orig_success.call(JSON.parse(text)) }
  
  self.request(options)
end