Welcome Guest, Not a member yet? Register   Sign In
help with xajax examples for codeigniter
#1

[eluser]suoko[/eluser]
I'm trying implementing the following example in codeigniter http://www.i-marco.nl/demo_en/demonstratie4.php
however I'm having problems.
Attached is my non-working code.

Here is the complete demo site: http://www.i-marco.nl/demo_en/demo.zip

CONTROLLER CODE:

Code:
<?php
Class Searching Extends Controller {
                    
function Searching()    {
    //ini_set('display_errors', 'On');
    parent::controller();
    $this->load->library('xajax');
    $this->xajax->registerFunction(array('getCities',&$this,'getCities'));
    $this->xajax->processRequest();
    }

function getCities($sSearch)  {
  $aCities = array(
                    "AaenHunze",
                    "Aalburg",
                    "Aalsmeer",
                    "Aalten",
                    "Abcoude",
                    "Achtkarspelen",
                    "Alblasserdam",
                    "Albrandswaard",
                    "Alkemade");
  $sOut = "";
  $nCount = 0;
  foreach($aCities as $sCity)  {
    $sPattern = "/^(".strtolower($sSearch).")/";
    if(preg_match($sPattern, strtolower($sCity)))  {
        $nCount++;
        $sOut .= "<li></li>";
        $sLastHit = $sCity;
      }
  }
  if($nCount > 31)  {
    $sOut = "";
    }
    $objResponse = new xajaxResponse();
  if(strlen($sOut) > 0)  {
    $sOut = "<ul>".$sOut."</ul>";
    $objResponse->addScript("document.getElementById('citybox').style.display = \"block\"");
  }
  else  {
    $objResponse->addScript("document.getElementById('citybox').style.display = \"none\"");
  }
if($nCount == 1)  {
    $objResponse->addScript("document.getElementById('citybox').style.display = \"none\"");
    $objResponse->addScript("document.getElementById('search').value = \"".$sLastHit."\"");
  }
    $objResponse->addAssign("citybox", "innerHTML", $sOut);  
    return $objResponse->getXML();
}

function index() {
    $template['head'] = $this->xajax->printJavascript();
    $template['xajax_js'] = $this->xajax->getJavascript(base_url() . "demo");
    $template['content'] = "&lt;input autocomplete=\"off\" type=\"text\" class=\"textbox\" name=\"search\" value=\"\" id=\"search\" onkeyup=\"xajax_getCities(document.getElementById('search').value);\"/&gt;<br />";
    $template['citybox_content'] = '<div id="citybox">&nbsp;</div>';
    $this->load->view('searching_view', $template);

    }

}
?&gt;

VIEW CODE:

Code:
&lt;html&gt;

&lt;head&gt;
&lt;title&gt;Searching 0.1 test&lt;/title&gt;
&lt;?=$head?&gt;
&lt;?=$xajax_js?&gt;
&lt;/head&gt;

&lt;body&gt;
Citta'<br>
&lt;?=$content?&gt;
&lt;?=$citybox_content?&gt;
&lt;/body&gt;

&lt;/html&gt;
#2

[eluser]mistress_shiira[/eluser]
what are the errors?
#3

[eluser]suoko[/eluser]
I'm going to compare "my" code and this one: http://www.alexajax.com/autosuggest
#4

[eluser]rvent[/eluser]
Sorry, but

Code:
whats with people not using the "code" tags....?
#5

[eluser]mistress_shiira[/eluser]
hey dont be too hard on him..i also forgot those tags once in a while before.Wink
and rvent is right,with that much code,you should put it between code tags...its kinda confusing.
#6

[eluser]suoko[/eluser]
sorry guys ... just fixed the post.
#7

[eluser]Đỗ Thanh Tùng[/eluser]
How about xajax library. I thinks that library cant be load




Theme © iAndrew 2016 - Forum software by © MyBB