简体   繁体   English

Javascript到Coldfusion,使用JavaScript中的变量在CF中使用

[英]Javascript to Coldfusion, using variable in javascript to query in CF with

Can I use a string array in my javascript file, pass it to a coldfusion page and use the elements in the array as parameters to search by in a < cfquery > ? 我可以在我的javascript文件中使用字符串数组,将其传递到Coldfusion页面,然后使用数组中的元素作为参数在<cfquery>中进行搜索吗?

.js .js

$.get("submit.cfm",{arr: obj}).done( function(data) {
    alert('The returned data is: ' + data);
});

.cfm .cfm

<cfparam name="tempArr" default = "" >

<cfset array = ArrayNew(6)>

<cfloop from="1" to="6" index="i">
     <cfset ArrayAppend(array, tempArr[i])>
</cfloop>

The code is incomplete, but how can I pass the values of obj (string array) from javascript to the variable tempArr in my coldfusion code 代码不完整,但是如何将javascript中obj (字符串数组)的值传递给我的Coldfusion代码中的变量tempArr

You would need to convert your array to JSON (JavaScript Object Notation), so you can pass it to the server via Ajax. 您需要将数组转换为JSON(JavaScript对象表示法),以便可以通过Ajax将其传递到服务器。 Then you would need to process the JSON into a server-side array structure. 然后,您需要将JSON处理为服务器端数组结构。

See this article for more details... 请参阅本文以获取更多详细信息...

Convert array to JSON 将数组转换为JSON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM