heispsychotic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-10 23:50 UTC
AJAX Serach Results
I have got Ajax.Request posting the data i need to the search backend, now the question is how do i return the data? I have onSuccess setup to read the returned text but really what im asking is what do i return form the processor? XML? CSV? And also how do i us this library to process the returrned information? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Well there may be better solutions depending on what language you''re
using server side and what your data is exactly, but I pretty much
always use JSON.
There is a library for it in pretty much every major language (I use php
with php_json.dll) and it''s usage is as simple as (PHP example):
$data = Array(''somekey''=>''sometext'');
print json_encode($data); //where $data is any combination of arrays and
associative arrays
On the client side, simply use eval. E.g.:
function json_decode(txt){
try{
return eval(''(''+txt+'')'');
}catch(ex){}
}
onSuccess: function(xhr,obj){
var results = json_decode(xhr.responseText);
alert(results.somekey); //alerts "sometext"
}
Or if you sent the results in an "X-JSON" header:
onSuccess: function(xhr,obj){
alert(obj.somekey); //alerts "sometext"
}
Colin
heispsychotic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
wrote:> I have got Ajax.Request posting the data i need to the search backend,
> now the question is how do i return the data? I have onSuccess setup
> to read the returned text but really what im asking is what do i return
> form the processor? XML? CSV? And also how do i us this library to
> process the returrned information?
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---