Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First thing to know is <a href="http://www.rahulsingla.com/blog/2010/05/jquery-encode-decode-arbitrary-objects-to-and-from-json" rel="noreferrer">jQuery Ajax requests do not encode arrays so have you to use something else to encode the data</a> (this is where jquery.JSON.js comes from referenced below). So with a the JSON encoded found there, I then figured out the correct syntax by working with <a href="http://cfquickdocs.com/cf8/?getDoc=cfajaxproxy#cfajaxproxy" rel="noreferrer">cfajaxproxy</a> and studying the URL it generates in Firebug:</p> <p><a href="http://localhost/remote.cfc?method=getResults&amp;argumentCollection=%7B%22q%22%3A%5B1%2C2%5D%7D" rel="noreferrer">http://localhost/remote.cfc?method=getResults&amp;argumentCollection=%7B%22q%22%3A%5B1%2C2%5D%7D</a></p> <p>Yes the "argumentcollection" approach is correct, and the variable "q" with a reference to an array is in there. </p> <p>I used the following code as a test bed:</p> <p><strong>remote.cfc</strong></p> <pre><code>&lt;cfcomponent output="false"&gt; &lt;cffunction access="remote" name="getResults" returntype="struct" returnformat="JSON" output="no"&gt; &lt;cfargument name="q" required="true" type="array" /&gt; &lt;cfreturn {a=1,b=2}&gt; &lt;/cffunction&gt; &lt;/cfcomponent&gt; </code></pre> <p><strong>remote.cfm</strong> to see how cfajaxproxy generates its url</p> <pre><code>&lt;cfajaxproxy cfc="Remote" jsclassname="Remote"&gt; &lt;cfoutput&gt; &lt;script language="javascript" type="text/javascript"&gt; var oRemote = new Remote(); alert(oRemote.getResults([1,2])); &lt;/script&gt; &lt;/cfoutput&gt; </code></pre> <p><strong>remote.html</strong> doing it with jQuery</p> <pre><code>&lt;script language="javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"&gt;&lt;/script&gt; &lt;script language="javascript" src="jquery.JSON.js"&gt;&lt;/script&gt; &lt;script language="javascript" type="text/javascript"&gt; var argumentCollection = { q: [1,2] }; $.ajax({ url: 'remote.cfc', data: { method: 'getResults', argumentCollection: $.JSON.encode(argumentCollection) }, success: function(response) { alert(response); }, dataType: 'json' }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload