Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

592
Views
Cómo mostrar el valor de retorno de la función ColdFusion usando jQuery o AJAX

Estoy usando la función ColdFusion que se muestra a continuación:

 <cffunction name="getdata" access="remote" output="true" returntype="string"> <cfargument name="x" type="string" required="true"> <cfargument name="y" type="string" required="true"> <cfquery name="getval" datasource="#application.datasource#" result="result"> select val from table where col1=#arguments.x# and col2=#arguments.y# </cfquery> <cfset p= #getval.val#> <cfreturn p> </cffunction>

Quiero que se imprima el valor de val en una alerta. La alerta que se muestra debe ser "verifique si es válido" cuando el usuario selecciona uno de los valores en el menú desplegable de autocompletar.

¿Cómo puedo conseguir esto?

Intenté usar jQuery AJAX dentro del evento de selección en autocompletar, aquí x e y son los nombres de los campos de entrada en el formulario:

 select: function(event, ui) { $.ajax({ type: "GET", url: 'somepathtofunction?method=getdata&x='+ x + '&y'+ y, async: true, success: function(result) { alert('please verify whether it is' + result.val ); } }); }

Además, probé el siguiente código:

 alert('please verify whether it is' + $.get('somepathtofunction?method=getdata&x='+ x + '&y'+ y));

pero ninguno de estos funcionó.

Soy nuevo en jQuery AJAX y ColdFusion, así que sé que he escrito la mayor parte del código incorrecto. Amablemente corríjame donde me equivoque.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Estás en el camino correcto con la llamada AJAX. Hay una multitud de maneras de lograr esto. He encontrado una de las formas más sencillas de hacer que tanto CF como JS utilicen la notación JSON. Su función CF debe establecerse en salida = verdadero y usar la función #serializeJSON()# para devolver los datos.

Un 'gotcha' a tener en cuenta es que CF siempre coapitaliza los datos JSON de manera predeterminada, por lo que debe usar la versión TODO EN MAYÚSCULAS de sus variables de retorno en el código JS que distingue entre mayúsculas y minúsculas.

Aquí hay algo para probar:

 <cffunction name="getdata" access="remote" output="true"> <cfargument name="x" type="string" required="true"> <cfargument name="y" type="string" required="true"> <cfquery name="getval" datasource="#application.datasource#" result="result"> select val from table where col1=#arguments.x# and col2=#arguments.y# </cfquery> <cfoutput>#serializeJSON({val=getval.val})#</cfoutput> </cffunction> $.ajax({ method: "GET", url: "yourCFCpathhere.cfc", data:{ method: "getdata", x: var1, y: var2 }, dataType: "json" }).done(function( result ) { alert('please verify whether it is' + result.VAL ); //CAPS for the return var from CF }); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!