Welcome Guest, Not a member yet? Register   Sign In
At my wit's end with Ajax.Updater
#1

[eluser]myerman[/eluser]
Having a lot of trouble (for some reason) with a VERY SIMPLE ajax application. Goes something like this:

* Db table called bars has ID, NAME, PHONE of bars (as in pubs)
* simple form asks for input from user
* form posts to javascript function that runs a controller function
* controller function runs model query, echos out results

When run as a normal form post, everything is great. But when I turn on the ajax.updater..nothing. Any thoughts would be great. Here's the code.

And yes, I started out the evening with Derek Allard's video tutorial...didn't work for me. I'm probably just really tired and can't see whatever it is that's in front of my face.


CONTROLLER
Code:
class NdaClub extends Controller {

    function NdaClub(){
        parent::Controller();
        $this->load->model('MBars','',TRUE);
    
    }
    
    function index(){
        $data['title'] = "NDA Club - Find a Bar!";
        $this->load->vars($data);
        $this->load->view('_ndaclub');
    }
    
    function findbar(){
        if ($this->input->post('searchterm')){
            echo $this->MBars->findBar($this->input->post('searchterm'));
        }else{
            echo "No form input!";
        }
    }

}



MODEL
Code:
class MBars extends Model {

    function MBars(){
        // Call the Model constructor
        parent::Model();
    }
    
    function findBar($term){
        $this->db->select('name,phone');
        $this->db->like('name',strip_tags($term));
        $this->db->orlike('phone',strip_tags($term));
        $this->db->orderby('name', 'asc');
        $Q = $this->db->get('bars');
    
        if ($Q->num_rows() > 0){
            echo "<ul>";
            foreach ($Q->result() as $row){
                echo "<li><b>".$row->name."</b> - ".$row->phone."</li>\n";
            }
            echo "</ul>";
        }else{
            echo "No bars found!";
        }
        //echo $this->db->last_query();
        //$Q->free_result();        
    
    }
  
  
}//end class



VIEW (partial)

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;



[removed]
//&lt;![CDATA[
var base_url = '&lt;?php echo base_url();?&gt;';
//]]>
[removed]
[removed][removed]
[removed][removed]
[removed]

ajaxSearch = function(){
    var url = base_url + 'ndaclub/findbar';
    var parms = "searchterm="+$F('term');
    new Ajax.Updater('search_results',
        url, {
            method:'post',
            evalScripts:true,
            postBody:parms,
            asynchronous:true,
            onComplete:showResponse
             }
        );
}

function showResponse(response){
   $('search_results')[removed] = response.responseText;
}

[removed]
&lt;/head&gt;

&lt;body class="oneColFixCtr"&gt;

<div id="container">
  <div id="mainContent">
    <h1>&lt;?php echo $title;?&gt;</h1>
  &lt;?php
    echo "&lt;form id='searchform' method='post'&gt;";
    $data = array('id'=>'term', 'name'=>'searchterm', 'size'=>25);
    echo form_input($data);
    echo form_submit('submit','find a bar');
    echo form_close();  
  
  ?&gt;
    <br/><br/>
    

    <div id="search_results"></div>


    </div>
</div>
&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 12:50 AM
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 10:20 AM
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 12:00 PM
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 01:45 PM
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 03:17 PM
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 04:13 PM
At my wit's end with Ajax.Updater - by El Forum - 07-30-2008, 09:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB