Hi list:
I'm a young developer that need a little help with scriptaculous 
"Autocompleter". I work with PRADO framework (http://www.xisc.com) and PHP as a 
script language. Now this is a little function in JavaScript for make a AJAX 
call and show the results without reload the entire page. See below:

1       function makeRequest(url,element) {
2               var http_request = false;
3               if (window.XMLHttpRequest) { // Mozilla, Safari,...
4                       http_request = new XMLHttpRequest();
5                       if (http_request.overrideMimeType) {
6                               http_request.overrideMimeType('text/xml');
7                       }
8               } else if (window.ActiveXObject) { // IE
9                       try {
10                              http_request = new 
ActiveXObject("Msxml2.XMLHTTP");
11                      } catch (e) {
12                              try {
13                                      http_request = new 
ActiveXObject("Microsoft.XMLHTTP");
14                              } catch (e) {}
15                      }
16              }       
17
18              if (!http_request) {
19                      alert('Información: No se ha podido crear la instancia 
del objeto XMLHTTP');
20                      return false;
21              }
22              http_request.onreadystatechange = function() { searchResult(); 
};
23              http_request.open('GET',"search_ajax.php?q="+element, true);
24              http_request.send(null);
25      }
26
27      function searchResult() {
28              if (http_request.readyState == 4) {
29                      if (http_request.status == 200) {
30                              alert(http_request.responseText); 
31                      } else {
32                              alert('Han ocurrido problemas con la 
petición.');
33                      }
34              }
35      }       

In search_ajax.php file I find the element in the database:
<?php
        $query = isset ( $_POST['qword'] ) ? trim ( rtrim ( $_POST['qword'] ) ) 
: null;
        if ( $query != null ){
                $db->Execute(" SELECT * FROM table WHERE field LIKE '%". $query 
."%' ") or die($db->ErrorMsg());
                $elements = array();
                while ( $record = $db->fetchRow() ){
                        $elements[] = $record;
                }
                return $elements;
        } else {
                return 0;
        }
?>

Now in line 30 is suppose that the result must be return to original page and 
assign this to DIV element. See the Autocompleter doc's I found this:

<input type="text" id="autocomplete"/>
        <div id="autocomplete_choices" class="autocomplete">
        </div>
</div>

So ... in "autocomplete_choices" element I need to show the result of the 
query, mean I need write the $elements content in this DIV. How can I do this? 
Any idea?
Regards,
-- 
ReynierPM 
4to. Ing. Informática 
Linux User: #310201
El programador superhéroe aprende de compartir sus conocimientos. Es el 
referente de sus compañeros. Todo el mundo va a preguntarle y él, secretamente, 
lo fomenta porque es así como adquiere su legendaria sabiduría: escuchando 
ayudando a los demás... 
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to