开发者

Coldfusion Ajax - Form Submission

I Need help with ColdFusion, I want to use the CF9 ajax library, I've got <cfajaximport tags="cfform"> in my header, and included a form using <cfdiv bind="url:domainchecker.cfm"> This however replaces the entire form with the "Loading" ajax wheel then shows the results.

What I need, is for开发者_如何学编程 the form to submit, but the a separate results area is what gets updated (and will obviously have the ajax "loading"). I don't want the entire area to to change (does that make sense??)


So, after much soul searching, I managed this:

<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>


I personally would use jQuery over CF Ajax functions for something beyond simple binding without too much additional JavaScript.

The provided JavaScript functions from CF are just too limited.

Since you're already used jQuery, this should be quite easy. Look at Ajax + Manipulation functions of jQuery.


Keep it simple?

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜