views:

321

answers:

1

This question is kind-of crappy because I try to get around some limitations:

Current JS sends an ajax query with the following code

jQuery('#searchbox').suggest('/?live=1');

What the server get is the following query string:

?live=1&q=searchstring

Problem: The server expects the query string to be preceded with 's=' not 'q='

I have to use the existing scripts so what I'm trying to so is find a way to change 'q=' to 's=' in javascript, without altering the exisiting suggest plugin or the php search script.

Thanks.

+1  A: 

The only way you will do that is by modifying the plugin, if you want to avoid changing the script forever and need this only for one page, override the function temporarily.

$.suggest.suggest = function() {
 var q = $.trim($input.val());
 if (q.length >= options.minchars) {
  cached = checkCache(q);
  if (cached) {
   displayItems(cached['items']);
  } else {
                //This is the line we r changing
          $.get(options.source, {s: q}, function(txt) {
    $results.hide();
    var items = parseTxt(txt, q);
    displayItems(items);
    addToCache(q, items, txt.length);
   });
  }
 } else {
  $results.hide();
 }
}
Dmitri Farkov
@dmitiri - doesn't seem to have any effect. How can you know which function take precedence ?
yoavf
Let me double check their code and get back to you.
Dmitri Farkov
As long as you put the code snippet provided AFTER the library loads it should work. Encapsulate the code snippet in $(function(){ SNIPPIT HERE }) to make sure it runs after all external resources are loaded.
Dmitri Farkov