T
Tony De
Hi all,
Perhaps someone experienced with XMLHttpRequest & ruby might be able to
help me. I don't know if it's my ruby code that is failing to properly
respond, or the javascript making the request and handling the response.
I've tried just prototype, just extjs, and as you can see, a mixin of
both as I try and figure out why I only get one response in return. The
only way I can get all of the results found in the search (server
script), is to build a really long string with results and pass just the
one "combined" result. I don't have any more hair to pull out.
tonyd
searchlog.rb
---------------------
#!/usr/local/bin/ruby -w
require 'cgi'
@cgi = CGI.new
# Our search params passed from our HTML page
sstring = @cgi['search']
slogtype = @cgi['logtype']
smethod = @cgi['method']
# A hash of possible logs
logs = {'smtp' => 'smtp', 'mail' => 'mails', 'mx' => 'mx', 'spam' =>
'spam', 'Dial Up' => 'radius', 'DHCP' => 'dhcp' }
# Send Response
def send_response(wts)
@cgi.header { "Content-Type: text/html" } # Not sure if this is
correct - Content? necessary?
@cgi.out{ "#{wts}" }
end
...
...
# Search through the log
File.open("/var/log/#{logs[slogtype]}",
'r').grep(/#{search_string}/).each do |line|
# This works but is not "live"..
response = response << "#{line}<br>" # append to response string
# This dosen't work - The end result is I only get one response back
at my javascript call
send_response( "#{line}<br>" ) # send response for each result
end
send_response( response ) # This in conjunction with building of
response string
...
...
searchlog.js
----------------
// Extjs JS Lib - extjs.com
Ext.onReady(function(){
// Disable the ENTER key from submitting the form
Ext.get('getinfo').on({
submit:function(e){
e.preventDefault();
return false;
}
});
// Handle form submission
Ext.get('submitButton').on('click', function(){
var pars = Form.serialize('getinfo');
var url = '/cgi-bin/search.rb'
ajaxUpdate(pars, url);
});
});
function ajaxUpdate(pars, url) { //Prototype.js function
var ajax = new Ajax.Updater({success: 'results-div', failure:
'results-div'}, url, {
method: 'get',
parameters: pars,
encoding: 'UTF-8',
insertion: Insertion.Bottom,
});
}
Perhaps someone experienced with XMLHttpRequest & ruby might be able to
help me. I don't know if it's my ruby code that is failing to properly
respond, or the javascript making the request and handling the response.
I've tried just prototype, just extjs, and as you can see, a mixin of
both as I try and figure out why I only get one response in return. The
only way I can get all of the results found in the search (server
script), is to build a really long string with results and pass just the
one "combined" result. I don't have any more hair to pull out.
tonyd
searchlog.rb
---------------------
#!/usr/local/bin/ruby -w
require 'cgi'
@cgi = CGI.new
# Our search params passed from our HTML page
sstring = @cgi['search']
slogtype = @cgi['logtype']
smethod = @cgi['method']
# A hash of possible logs
logs = {'smtp' => 'smtp', 'mail' => 'mails', 'mx' => 'mx', 'spam' =>
'spam', 'Dial Up' => 'radius', 'DHCP' => 'dhcp' }
# Send Response
def send_response(wts)
@cgi.header { "Content-Type: text/html" } # Not sure if this is
correct - Content? necessary?
@cgi.out{ "#{wts}" }
end
...
...
# Search through the log
File.open("/var/log/#{logs[slogtype]}",
'r').grep(/#{search_string}/).each do |line|
# This works but is not "live"..
response = response << "#{line}<br>" # append to response string
# This dosen't work - The end result is I only get one response back
at my javascript call
send_response( "#{line}<br>" ) # send response for each result
end
send_response( response ) # This in conjunction with building of
response string
...
...
searchlog.js
----------------
// Extjs JS Lib - extjs.com
Ext.onReady(function(){
// Disable the ENTER key from submitting the form
Ext.get('getinfo').on({
submit:function(e){
e.preventDefault();
return false;
}
});
// Handle form submission
Ext.get('submitButton').on('click', function(){
var pars = Form.serialize('getinfo');
var url = '/cgi-bin/search.rb'
ajaxUpdate(pars, url);
});
});
function ajaxUpdate(pars, url) { //Prototype.js function
var ajax = new Ajax.Updater({success: 'results-div', failure:
'results-div'}, url, {
method: 'get',
parameters: pars,
encoding: 'UTF-8',
insertion: Insertion.Bottom,
});
}