Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can either use setInterval or setTimeout depending on how you want to do things. You may also want to use clearInteval or clearTimeout to prevent the refreshing in certain situations.</p> <p>For the AJAX stuff, you can use jQuery's functions, the example below uses getJSON which is more lightweight than HTML (which the jQuery.get woudl do), but this means processing it to create the HTML on the client.</p> <p>For example:</p> <pre><code>$j = jQuery.noConflict(); $j(document).ready( initSearching ); function initSearching() { Searching = setInterval( 'updateSearch()' , 5000 ); // 5s while testing... $j('#StopRefreshBtn').click( stopSearching ); } function stopSearching() { clearInterval(Searching); } function updateSearch() { if ( $j('#SearchBox').val().length &gt; 0 ) { sendSearchRequest( $j('#SearchBox').val() ); } } function sendSearchRequest( SearchTerms ) { $j.getJSON( 'http://www.myserver.com/webservices/mycfc.cfc?method=readData&amp;SearchTerms='+SearchTerms , handleSearchResponse ); } function handleSearchResponse( SearchResults ) { console.log( SearchResults ); // TODO: Handle JSON response to render the HTML results. } </code></pre> <p><br/> Then, on the CF side, you just need a component with a remote function - and since I'm doing it with JSON, the returnformat is set to that:</p> <pre><code>&lt;cfcomponent output="false"&gt; &lt;cffunction name="readData" returntype="array" output="false" access="remote" returnformat="json"&gt; &lt;cfargument name="SearchTerms" type="String" /&gt; &lt;cfset var Results = ArrayNew(1)/&gt; &lt;!--- TODO: search and populate array of results. ---&gt; &lt;cfreturn Results /&gt; &lt;/cffunction&gt; &lt;/cfcomponent&gt; </code></pre> <p><br/> The above is all quickly thrown together and not tested - hopefully if anyone sees problems with it they'll point them out.</p> <p>For more details on doing remote requests with jQuery and ColdFusion, there are some answers to this similar question: <a href="https://stackoverflow.com/questions/999501/invoke-coldfusion-function-using-ajax">Invoke ColdFusion function using AJAX</a></p> <p>Hopefully that all makes sense, and gets you heading in the right direction?</p>
    singulars
    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