Coldfusion Ajax - 表单提交

发布于 2024-09-06 13:23:01 字数 272 浏览 6 评论 0原文

我需要 ColdFusion 方面的帮助,我想使用 CF9 ajax 库,我的标头中有 ,并包含一个使用 < cfdiv bind="url:domainchecker.cfm"> 然而,这会用“正在加载”ajax 轮替换整个表单,然后显示结果。

我需要的是提交表单,但是单独的结果区域会被更新(并且显然会有ajax“加载”)。我不想改变整个区域(这有意义吗??)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

几味少女 2024-09-13 13:23:01

因此,经过一番深思熟虑,我做到了:

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

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>
顾忌 2024-09-13 13:23:01

我个人会使用 jQuery 而不是 CF Ajax 函数来实现简单绑定以外的功能,而无需太多额外的 JavaScript。

CF 提供的 JavaScript 函数只是太有限了。

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

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.

白昼 2024-09-13 13:23:01

保持简单吗?

域搜索.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>

搜索处理器.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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文