views:

197

answers:

1

i m using auto suggest using Ajax Json .

now when a user select a user name , i want to send user on the link of that user name

my json data is coming in this way

{
 query:'hel',
 suggestions:["hello world","hell boy ","bac to hell"],
 data:["2","26","34"]                       
}

now what i want that user goes to http://userProfile.php?uid=26 on select username(suppose user select "hell boy") how to do this??

UPDATE: i describe what i m doing step by step i m using a searchbox using jquery ajax, when user write some text on input box , we show (suggest) value regarading their search

STEP 1. when user write atleast(2 letter) <input type="text" name="q" id="query" />then a function(below) in invoked in which i send the value written on text box(eg. hell).

<script type="text/javascript" language="javascript">
    var options, a;
    jQuery(function(){
       options = { serviceUrl:'rpc.php' };
       var a = $('#query').autocomplete({ 
        serviceUrl:'rpc.php',
        minChars:3, 
        delimiter: /(,|;)\s*/, // regex or character
        maxHeight:400,
        width:300,
        zIndex: 9999,
        deferRequestBy: 0, //miliseconds
      });
    });
 </script>

STEP 2: on rpc.php, i collect the data and show using JSON my final data come in below format

{
 query:'hell',
 suggestions:["hello world","hell boy ","bac to hell"],
 data:["2","26","34"]                       

}

where suggestion list having username and data is userid( from user_tables). above data comes in a div (on frontend) where user name displayed in a list

STEP 3: now if i select any username using uparrow, downarrow then that name is filled in input box, STEP 4: now what i want that when user select usename then page automatically goes to that user's profile section ( userprofile.php?uid=2)

+1  A: 

if you look at the page you linked, under the "how to use" section, you will see you can add an onSelect callback function:

 // callback function:
onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },

Now you should be able to access you data, and move your user to your required page.

e.g. something like the following:

<script type="text/javascript" language="javascript">
var options, a;
jQuery(function(){
   options = { serviceUrl:'rpc.php' };
   var a = $('#query').autocomplete({ 
    serviceUrl:'rpc.php',
    minChars:3, 
    delimiter: /(,|;)\s*/, // regex or character
    maxHeight:400,
    width:300,
    zIndex: 9999,
    deferRequestBy: 0, //miliseconds
     // callback function:
    onSelect: transferUser },
  });
});

function transferUser(value, data)
{
window.location.href = 'userprofile.php?uid=' + data;
}
</script>

(note that I've not tested this, but it should give you some idea as to how to proceed!)

It may also be worth noting that the latest version of jQuery UI also has autocomplete

Zeus
Thanks! that is i want exactly
diEcho