Re: serializeJson

Cristian Costantini <[email protected]>
Newsgroups gmane.comp.cms.cold-fusion.devel.italian
Message-ID <[email protected]>
Ciao,

no, puoi fare da parametro url myComponent.cfc?method=myMethod&returnformat=json oppure nella cffunction aggiungi l'attributo returnformat="json"

nella function di cf elimina il serializeJSON e ritorna il tipo Array.
CF convertirà in automatico in JSON o WDDX (default)

http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f5c.html

Cristian

Il giorno 20/set/2012, alle ore 19.22, Vittorio Carlo Granata ha scritto:

> dove esattamente , nella function javascript?
> 
> 
> questo è il codice
> 
> <script type="text/javascript">
> $(document).ready(function() {
>     $('#fromp').change(function() {
>         if ($('#fromp').val() !="0") {
>            
> 				$.getJSON("components/contenuti.cfc?method=gettoplace",{idfrom: $(this).val()}, function(jsonData){
>                 $.each(jsonData, function(i, data) {
>                         cb='<option value="'+data.IdFrom+'">'+data.FromPlace+'</option>';
>                         $('#topp').append(cb);
>                 });
>             });
> 
>         }
>     });
> });
> </script>  
> 
> 
> Vittorio Carlo Granata
> [email protected]
> 
> 
> 
> Il giorno 20/set/2012, alle ore 18:54, Cristian Costantini ha scritto:
> 
>>  
>> Ciao,
>> 
>> 
>> prova con returnFormat="json" nella function
>> 
>> Cristian
>> 
>> Il giorno 20/set/2012, alle ore 17.58, Vittorio Carlo Granata ha scritto:
>> 
>>>  
>>> Ciao Ragazzi.
>>> 
>>> 
>>> Sto realizzando un modulo con un select che si popola con con i dati di una funzione in un cfc
>>> il classico regione----- provincia
>>> 
>>> il mio problema è che la stringa json restituita non viene interpretata dalla funzione jquery 
>>> in pratica la stringa è:
>>> 
>>> <wddxPacket version='1.0'><header/><data><string>[{"FromPlace":"Aereoportto Ciampino","IdFrom":2},{"FromPlace":"Civitavecchia Porto","IdFrom":3},{"FromPlace":"Roma","IdFrom":4},{"FromPlace":"Stazione Termini","IdFrom":5}]</string></data></wddxPacket>
>>> invece di 
>>> 
>>> [{"FromPlace":"Aereoporto Fiumicino","IdFrom":1},{"FromPlace":"Aereoportto Ciampino","IdFrom":2},{"FromPlace":"Civitavecchia Porto","IdFrom":3},{"FromPlace":"Stazione Termini","IdFrom":5}]
>>> 
>>> 
>>> la funzione è la seguente
>>> 
>>> <cffunction name="gettoplace" access="remote" returntype="string">
>>> <cfargument name="idfrom">
>>>  <cfset var Rs_listto = "" >
>>>   <cfquery name="Rs_listto" datasource="#request.ds#">
>>> SELECT dbo.TabFrom.IdFrom, dbo.TabFrom.FromPlace 
>>> FROM dbo.TabFrom 
>>> where dbo.TabFrom.IdFrom <> #arguments.idfrom#
>>> 
>>>   </cfquery>
>>> 
>>> <cfset var result=ArrayNew(1)>
>>> 
>>> <!--- Build result array --->
>>> <cfloop query="Rs_listto">
>>> <cfset returnStruct = StructNew() />
>>> <cfset returnStruct["IdFrom"] = Rs_listto.Idfrom>
>>> <cfset returnStruct["FromPlace"] = Rs_listto.FromPlace>
>>> <cfset ArrayAppend(result,returnStruct) />
>>> </cfloop>
>>> 
>>> <!--- And return it --->
>>> <cfreturn serializeJSON(result) />
>>> 
>>> </cffunction>
>>> </cfcomponent>
>>> 
>>> sto sbagliando qualcosa?
>>> 
>>> Vittorio Carlo Granata
>>> [email protected]
>>> 
>>> 
>>> 
>>> 
>> 
>> 
> 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.