简体   繁体   English

麻烦让JavaScript代码从mysql检索数据

[英]trouble having a javascript code retrieve data from mysql

I am in a little bit of a predicament. 我有点困境。 I am writing a programme where a user can make a search. 我正在编写一个程序,用户可以在其中进行搜索。 Then the search returns a possible list of results. 然后搜索返回可能的结果列表。 If you move your mouse over the results it highlights them. 如果将鼠标移到结果上方,它将突出显示它们。 When you select one of the items from the result, it replaces the list with the item you selected. 当您从结果中选择一项时,它将列表替换为您选择的项。 The problem I am having is that I can't get the item to replace the list. 我遇到的问题是我无法获得替换列表的商品。 I am using CodeIgniter. 我正在使用CodeIgniter。

Steps 脚步

In my model, I pass the id (VenueID) of item through onclick function to my javascript function. 在我的模型中,我将项目的ID(VenueID)通过onclick函数传递给我的javascript函数。

venue_model.php : place_model.php

$output .= '<li><a href="#self" class="menulink" class=&{ns4class};
               onClick="changeDiv(\''.
                 $venue_details->**VenueID**.

               '\')">

The javascript function takes the javascript id and then passes it to a function in the controller to retrieve the item from a MySQL database. javascript函数获取javascript id,然后将其传递给控制器​​中的函数,以从MySQL数据库中检索项目。

divUpdater.php : divUpdater.php

<script type="text/javascript">
base_url = '<?= base_url();?>index.php/';
</script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">

function changeDiv(venueID){
  $.get(base_url+'home/get_venue_description/' + venueID , function(data) {
    $('#venue_description').html(data);
    document.getElementById('venue_description').innerHTML=data;
  });

}

here is the function from the controller that retrieves the data from the database 这是控制器中从数据库检索数据的功能

home.php (controller) home.php (控制器)

    function get_venue_description($venueID){
       echo $this->venue_model->retrieveData($venueID);
      }

The problem is in the model and the divUpdater.php. 问题出在模型和divUpdater.php中。 When I click on one of the item from the list, it gives me this url 当我单击列表中的一项时,它给了我这个网址

http://localhost/Counter/index.php#self

And this is becasue of the anchor tag in the model ( <a href="#self"... ). 这是因为模型中的锚标记( <a href="#self"... )。 I was wondering if it was possible to get the code in the divUpdater.php to execute and retrieve the data in the background without having the url change. 我想知道是否可以在divUpdater.php中获取代码以在后台执行和检索数据而无需更改url。

Please does anyone know how to do that? 请问有人知道该怎么做吗?

If you do not want the default click behavior of a link to occur (going to #self when clicking a link with href="#self"), then your onclick handler should return false. 如果您不希望发生链接的默认单击行为(在单击带有href =“#self”的链接时转到#self),那么您的onclick处理程序应返回false。

onClick="changeDiv(stuff); return false;"

I don't know if that will help with anything else. 我不知道这是否对您有帮助。

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

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