Вопрос

I have an update query to which I am passing a JavaScript array called "newdata", obviously, that didn't work so I don't know how to pass my JavaScript variables to ColdFusion in order to run an update query. How I can see surfing some webs? ColdFusion doesn't have access to Javascript variables. Here's my code, regards!

<cfquery name="updatereserva" datasource="Prueba">
    UPDATE reserva_habitac 
    SET FechaENTRADA = newdata["#firstdate#"]
    WHERE idRESERVA = newdata["idreserva"]                  
</cfquery>

Is there another way to do this?

Это было полезно?

Решение

There are several ways.

  • You could put the JavaScript variables into a form, and submit that to a specific page in your app.
  • You could execute an AJAX request that posts your JavaScript array as JSON to the desired page in your application
  • Etc.

ColdFusion has some built in support for AJAX, but there are also a ton of JS libraries and frameworks that could do just as good (if not way better) of a job. There is, after all, nothing ColdFusion-specific about an AJAX request; CF just ships with some functionality to help, if you want to use that.

The important thing is that in designing your app, you need to remember that JavaScript and ColdFusion operate in different contexts--the former on the client (browser), the latter on the server. While this is certainly not an impediment to making a very robust JavaScript-fronted app (or even an app that just used JavaScript here and there to talk to ColdFusion), you do have to design a bit differently than you would with a non-JS app, so it's important to get the difference clear and go from there.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top