Welcome Guest, Not a member yet? Register   Sign In
Ajax and CI : I am lost
#1

[eluser]TDSPower[/eluser]
Hello,

I am working on my CI project.

I meet an error with the Autocompletion with the CI Ajax Library.

I create a controller which will show the form :

Code:
class Accueil extends All_accueil {
...
        function test(){
            $this->load->view('javascript_test');
        }
        
        function auto(){
              echo("<ul id=\"categorie_auto_complete\"><li>TEst</li><li>123</li></ul>");
        }
...
}

Here is the view (form), the input type text categorie is normally autocompleted (with the LI created with auto())...
Code:
&lt;form action="test.hpp" name="a"&gt;

<div id=\"categorie_auto_complete\" style="height:30px; width:100px; background-color:grey;"></div>
        &lt;input type="text" id="categorie" name="categorie" size="20"&gt;
        &lt;input type="submit" value="Tester"&gt;
&lt;?
echo $this->ajax->auto_complete_field('categorie',array('url' => '/accueil/auto'));
?&gt;

Nothing appears when i write some text on the input text...

When I look on firebug :
Quote:Erreur : $(element) has no properties
Fichier source : http://localhost/magnet/system/javascript/prototype.js
Ligne : 987

Don't understand where is the problem with such an implicit error !

Thanks a lot,

François
#2

[eluser]sandwormusmc[/eluser]
I'm not too familiar with the prototype framework, but it looks like it's having trouble selecting the id of the element on line 987 of the prototype.js code. Can you post that snippet of code also?

In MooTools, which I've been (successfully, so far) using with CI, I can call /controller/functionName through an AJAX call and specify the updated id within the ajax object as such:

Code:
--removed--

Is it a similar setup with Prototype?
#3

[eluser]Michael Wales[/eluser]
We need to see your Javascript.
#4

[eluser]TDSPower[/eluser]
Thanks for these very fast answers... I don't think the problem is in the prototype javascript ! It is a JS Framework reference as you know.

I post some line where the error is indicated :
Quote: hide: function(element) {
$(element).style.display = 'none';
return element;
},

show: function(element) {
$(element).style.display = '';
return element;
},

remove: function(element) {
element = $(element);
element[removed].removeChild(element);
return element;
},
#5

[eluser]sandwormusmc[/eluser]
Try using this in your view instead of what you have:

Code:
echo $this->ajax->auto_complete_field('changeMe*',array('url'=>'/accueil/auto','update'=>'categorie'));

The 'update' parameter should specify which DOM ID the JavaScript will change when it runs ...

*<change this to the DOM ID of your form>
#6

[eluser]Pascal Kriete[/eluser]
Could you post the code that gets generated here:
Code:
echo $this->ajax->auto_complete_field('categorie',array('url' => '/accueil/auto'));
I'm not familiar with the library, but I do use prototype on a regular basis and it works fine with CI.
#7

[eluser]TDSPower[/eluser]
I am so a dumb... I do not deserve your precious help...

I put scriptaculous before prototype...



And we have to put :


For others noobs, I put the final code :
Code:
&lt;?
$this->load->helper('url');
//echo base_url().'system/javascript/prototype.js';
?&gt;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;javascript_test&lt;/title&gt;
  
  
&lt;/head&gt;
&lt;body&gt;

  &lt;form action="test.hpp"&gt;
    &lt;input type="text" id="categorie" name="categorie" size="20" /&gt;
    <div id="blabla">qqqqqqqqq</div>
    &lt;input type="submit" value="Tester" /&gt;
    &lt;?
  echo $this->ajax->auto_complete_field('categorie', array('update' => 'blabla','url' => 'auto'));
  ?&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Sorry again
#8

[eluser]Nick Husher[/eluser]
Just so you know, the ExpressionEngine Forum is wreaking havoc on your examples. It'll hack out anything that even starts to resemble a cross-site scripting attack. Wink
#9

[eluser]TDSPower[/eluser]
I'll protect my DB query, no problem. Thanks
#10

[eluser]porky_voice[/eluser]
Greetings!

Having a hard time on using ajax:

$this->ajax->auto_complete_field('username', array('url' => 'controller/ajax_search', 'update' => 'div id'));

instead of displaying the list or username, it display the whole webpage like (controller/index).

i wonder why.. i'm newbie BTW.

Thanks for sharing your small time.




Theme © iAndrew 2016 - Forum software by © MyBB