简体   繁体   中英

Troubles using jquery get to retrieve data from the server and place in a div

I am new to jquery and I am having problems trying to retrieve an item from the database and display the results. I am using codeigniter php.

What i am trying to do is this. I do a search, the search returns a list of posible results which is displayed in a div called venue_description. Onclick of one of the items from the list, I want it to replace the list with the item that is being clicked upon. but for some reason it does not work

In order to do that I did this:

In my model I pass the id of the item that is being clicked upon on the list through the onclick function

<--- this is in venue_model.php -->

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

The venueID is passed through the changeDiv which is in the divUpdater.php This is where the problem is. The $.get doesn't work. Can someone see the mistake? The Item retrieved is to be displayed in venue_description div

<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);

        });
    }
</script>

changeDiv(venueID) calls the get_venue_description(venueID) in the home.php controller to retrieve the specific item from the database.

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

Can anyone see the problem in this code? I have spent too much time try to find the mistake. Please help!

Do you have firebug installed so you can check that the get is being fired?

maybe you can change this to echo debug string to test the problem is not in the model.

function get_venue_description($venueID){
    echo 'This is a test responce';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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