Coldfusion Ajax - 表单提交

时间:2010-06-21 05:31:55

标签: jquery ajax coldfusion cfform

我需要帮助ColdFusion,我想使用CF9 ajax库,我的标题中有<cfajaximport tags="cfform">,并且使用<cfdiv bind="url:domainchecker.cfm">包含一个表单但是这会将整个表单替换为“加载“ajax wheel然后显示结果。

我需要的是提交表单,但单独的结果区域是更新的(并且显然会有ajax“loading”)。我不希望整个区域发生变化(这有意义吗?)

3 个答案:

答案 0 :(得分:1)

所以,经过多次灵魂寻找,我设法做到了:

<head>
...
<cfajaximport />
...
    <script>
        function handleResponse(s) {
            if(s == "AVAILABLE") {
                //rewrite span
                var domainspan = document.getElementById('DomainStatus');
                var newcontent = "Available To Register :)";
                domainspan.innerHTML = newcontent;
                var loadingspan = document.getElementById('frmGO');
                var newcontent = "<input name='' value='GO!' class='search_domain_go' type='submit' />";
                loadingspan.innerHTML = newcontent;
            } else {
                //rewrite span
                var domainspan = document.getElementById('DomainStatus');
                var newcontent = "Unavailable To Register :(";
                domainspan.innerHTML = newcontent;
                var loadingspan = document.getElementById('frmGO');
                var newcontent = "<input name='' value='GO!' class='search_domain_go' type='submit' />";
                loadingspan.innerHTML = newcontent;
            }
        }

        function CheckDomain() {
            var loadingspan = document.getElementById('frmGO');
            var newcontent = "<input name='' type='image' class='search_domain_go' src='images/ajax-loader.gif' alt='' />";
            loadingspan.innerHTML = newcontent;
            ColdFusion.Ajax.submitForm('frmDomainCheck','checkdomain.cfm',handleResponse);
        }
    </script>
...
</head>

<body>
...
        <div class="search_domain">
            <div class="search_domain_form">
            Search Your Domain Here<br />
                <form method="post" action="" onSubmit="CheckDomain();return false;" id="frmDomainCheck">
                    <input class="search_domain" name="frmURL" id="frmURL" value="Please enter your domain name here..." onfocus="if(this.value == 'Please enter your domain name here...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Please enter your domain name here...';}" type="text" />
                    <span id="frmGO"><input name="" value="GO!" class="search_domain_go" type="submit" /></span>
                <form>
            </div><!-- /# end search form -->
            <div class="domain_features">
                <ul>
                    <li><span id="DomainStatus">Type in the domain and click 'GO' to check its availability.</span></li>
                </ul>
            </div>
        </div>
...
</body>

答案 1 :(得分:0)

我个人会使用jQuery而不是CF Ajax函数来实现简单绑定之外的东西而不需要额外的JavaScript。

来自CF的provided JavaScript functions太有限了。

由于你已经使用过jQuery,这应该很容易。看看jQuery的Ajax + Manipulation函数。

答案 2 :(得分:0)

保持简单?

domainSearch.cfm

<head>
</head>

<body>
<h2 style="color:Blue">Domain search</h2>
<form name="domainSearch">
www.<input class="search_domain" name="searchString" id="frmURL" value="Please enter your domain" onfocus="if(this.value == 'Please enter your domain') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Please enter your domain';}" type="text" />.com
<font color="#FF0000"><strong>[Search]</strong></font>
</form>
<p>Enter any domain.com, (hint: try "free")</p>
<cfdiv id="resultsDiv" bind="url:searchProcessor.cfm?searchString={searchString}">
</body>
</html>

searchProcessor.cfm

<cfif IsDefined("URL.searchString")>

    <cfif URL.searchString eq "Please enter your domain">
        <cfoutput></cfoutput>   
    <cfelseif URL.searchString eq "free">
        <cfoutput>Great, #URL.searchString# is available, price $400</cfoutput>
    <cfelse>    
        <cfoutput>Sorry, #URL.searchString# is not available, try again.</cfoutput>
    </cfif>
</cfif>