[HTML_AJAX-devel] How to identify origin of async request in
callback?
Krzysztof Kotowicz
koto1sa at o2.pl
Tue Aug 15 06:55:03 PDT 2006
Hi! I'm developing a small dictionary-like application using HTML_AJAX
package (0.4.1 alpha).
It's a form where i'm assigning certain entities (let's say - products)
from a database to another entities (e.g. groups of products)
The interface contains of several product rows, one cell of each row
being an INPUT field with appropriate assigment for this product (group
name), e.g.
Product name, Product price, Quantity, Group
Pear, 1.40, 2, <fruits>
Chair, 42.00, 1, <furniture>
I'm trying to create an autocomplete functionality for the group
fields. I'm using async calls to communicate with the server (requests
are made during onkeyup event on a field and are later processed by a
single callback function)
My question is - how could I instruct callback function that a request
that it is processing is related to a specified field?
I have such information during sending the event (
onkeyup="get_suggest(this,this.nextSibling)" ) - how can I store it so
that callback function knows which field to update / where to display
the results? This is not to be confused with async method call
parameters (the field name is irrelevant for the PHP class in the backend).
Related current code (I'm using jquery):
<script type="text/javascript"
src="server.php?client=Util,main,dispatcher,httpclient,request,json,loading"></script>
<script type="text/javascript" src="server.php?stub=ci_items"></script>
var ciCallback = { // callback for async calls
getItemsStartingWith: function(result) {
// currently is just writes to #target, i'd like the code to update
// the appropriate .auto_complete div for appropriate field
calling the method
// the DIV is passed as the target parameter in get_suggest() function
var a;
$('#target').html('');
for (var i in result) {
a = $.A({'class': 'chooseitem', href: '#', title:
result[i].name}, i);
$("#target").append(a);
}
}
}
var ci = new ci_items(ciCallback); // ci_items is a HTML_Ajax proxy
class for appropriate PHP class
function get_suggest(obj, target) {
ci.getItemsStartingWith(string); // returns JS array
}
<td>
<input autocomplete="off" type="text" name="ci_item[111][id]"
value="KILTJM" onkeyup="get_suggest(this,this.nextSibling)" />
<div class="auto_complete"></div>
</td>
Thank you for all the suggestions,
Chris Kotowicz
More information about the Html_ajax-devel
mailing list