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.
在我的模型中,我通过onclick函数将项目的id(VenueID)传递给我的javascript函数。
venue_model.php:
venue_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. When I click on one of the item from the list, it gives me this url
问题出在模型和divUpdater.php中。当我点击列表中的一个项目时,它会给我这个网址
http://localhost/Counter/index.php#self
And this is becasue of the anchor tag in the model (<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.
Please does anyone know how to do that?
请问有谁知道怎么做?
1 个解决方案
#1
1
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;"
onClick =“changeDiv(stuff); return false;”
I don't know if that will help with anything else.
我不知道这是否有助于其他任何事情。
#1
1
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;"
onClick =“changeDiv(stuff); return false;”
I don't know if that will help with anything else.
我不知道这是否有助于其他任何事情。