Apologies, now looking back, I've noticed that your calling ajax.get, not $.get, d'oh.
Personally, i'd not send this request via GET, but as I have above, via POST. Does your ajax library have the ability to send a post request?
Based on my code, $.ajax returns a httpwebrequest object and performs a POST request with a form variable of "Query" set to the keywords you type in.
Then on completion (assuming it completes ok), it then automatically parses the response to json format, similar to what your doing.
If you don't want to use POST, try and see if you can return the xmlhttprequest in your ajax.get query and within the callback function, eval it as you have and then call the associate_search.doSearch callback with the eval'd object.
var associate_search =
this.last_query = '';
this.last_results = new Array();
this.ajax_request = null;
// takes the keywords (a string)
// and a callback (a function with
// one single param)
this.doSearch = function(keywords, callback)
// if the user is still typing,
// kill any previous searches
if(this.ajax_request != null)
// call the abort method on your xhr
// if the last query is the same
// as the current one, return
// the last set of results
if(this.last_query == keywords)
// set the last_query to the current keywords
this.last_query = keywords;
// store a local copy of "this",
// so it can be accessed
var em = this;
// create an ajax request and
// store the request in the
// ajax_request variable (to
// abort if need be
em.ajax_request = ajax.get('path to script', function(response)
var data = eval('(' + response + ')');
em.last_results = data;
// clear the ajax_request
em.ajax_request = null;
// fire the callback with the results
// return the ajax_request
// the instance of associate_search
var as_instance = null;
// if the instance hasn't
// been defined, create it
if(as_instance != null)
as_instance = new associate_search();
// perform the search, passing
// the value of the text box
// and a callback function.
// once we have got some results, so something with them!
Edit: Apologies, you'd need to change the keyup event I'd added to work with your own code.
A bit of advice... I used to use my own libraries and within about 10 minutes of using jQuery, I noticed that I was wasting my time. jQuery will save you a LOT of time in the long run.