jQuery没有发布 - (jQuery - ColdFusion)

 全球时_尚热门焦点吧 发布于 2023-02-12 16:25

我有一个小函数,使用ColdFusion 9和jQuery从我的数据库中删除记录

该函数存在于其他3个位置,它是相同的并且按预期运行,但它似乎与此页面有错误.

Html表单代码

  ID Category Name
#recID# #categoryname#

jQuery的

function dlteCatR(field)
{               
    var $srt = $(field);
    var r = confirm("Are you sure you want to delete this Category? \n You will not be able to revert this change!")
    if(r==true){
        for(i=0; i<$srt.length; i++){   
            if($srt[i].checked == true){
                var url="surveyAdmin.cfc?wsdl&method=deleteRateCat&recId="+$srt[i].value;
                $.post(url);
            }
        }
        window.location.reload();
    }else{
        return false;
    }
}

surveyAdmin.cfc方法


    
    
        delete from rating_categories
        where id = 
    

我正在使用firebug来跟踪电话,但它没有给我任何好的解释,说明它为什么不起作用.

此外,当我在firebug中复制链接并在浏览器中自行运行时,事务正在发生

1 个回答
  • $.post()发送异步请求.如果在请求完成之前重新加载页面,则请求将中止.

    在您的情况下,您在for循环中一次发送n个请求,然后window.location.reload();在任何有时间完成之前立即重新加载页面(使用此行).要解决此问题,您可以将它们全部合并到一个$.post请求中并使用成功回调,或者您可以存储从$.post()数组中返回的每个promise对象并将其传递给$.when.

    我建议使用第一个将所有请求合并为一个请求并使用成功回调的解决方案,但是这需要您修改当前的cfc方法以接受多个记录一次删除,或者创建一个新的cfc方法可以处理它.

    一种方法是让您的方法能够处理id的列表而不是单个id.

    <cffunction name="deleteRateCat" access="remote" returntype="void" output="no"  hint="Delete Rating Categories.">
        <cfargument name="recID" type="string" required="true" hint="The id of the rating category to delete.">
        <cfquery datasource="#dsn#">
            delete from rating_categories
            where id in (<cfqueryparam cfsqltype="cf_sql_integer" value="#ListAppend(arguments.recID, 0)#" list="yes">)
        </cfquery>
    </cffunction>
    

    和js一起去:

    function dlteCatR(field){               
        var r = confirm("Are you sure you want to delete this Category? \n You will not be able to revert this change!")
        if(r==true){
            var recIdList = $("[name=" + field + "]:checked").map(function(){
                return this.value;
            }).get().join(",");
            var url="surveyAdmin.cfc?wsdl&method=deleteRateCat&recId="+recIdList;
            $.post(url).done(function(){
                window.location.reload();
            });        
        }
    }
    

    2023-02-12 16:28 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有