简体   繁体   English

使用 ajax jquery 发送关于 json 数据的链接

[英]send link on json data using ajax jquery

im using auto suggest using Ajax Json .我使用自动建议使用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我的 json 数据是这样来的

{
 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??现在我想要那个用户在选择用户名时转到http://userProfile.php?uid=26 (假设用户选择“hell boy”)怎么做??

UPDATE: i describe what im doing step by step im using a searchbox using jquery ajax, when user write some text on input box , we show (suggest) value regarading their search更新:我使用 jquery ajax 使用搜索框一步一步地描述了我在做什么,当用户在输入框上写一些文本时,我们显示(建议)关于他们的搜索的价值

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).步骤 1.当用户写至少(2 个字母) <input type="text" name="q" id="query" />然后调用一个函数(下面),我发送写在文本框上的值(例如。 地狱)。

<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第 2 rpc.php rpc.php ,我收集数据并使用 JSON 显示我的最终数据采用以下格式

{
 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).其中具有用户名和数据的建议列表是 userid(来自 user_tables)。 above data comes in a div (on frontend) where user name displayed in a list以上数据来自一个 div(在前端),其中用户名显示在列表中

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 )第 3现在,如果我使用向上箭头、向下箭头选择任何用户名,然后在输入框中填写该名称,第4现在我想要的是,当用户选择 usename 时,页面会自动转到该用户的个人资料部分( userprofile.php?uid=2 )

if you look at the page you linked , under the "how to use" section, you will see you can add an onSelect callback function:如果您查看 您链接页面,在“如何使用”部分下,您将看到您可以添加一个onSelect回调函数:

 // 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.现在您应该能够访问您的数据,并将您的用户移动到您需要的页面。

eg 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可能还值得注意的是,最新版本的 jQuery UI也有自动完成功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM