jQuery not posting - (jQuery - ColdFusion)
jQuery not posting - (jQuery - ColdFusion)
我有一个小函数,可以使用ColdFusion 9和jQuery 从数据库中删除记录
该函数存在于其他3个位置,它与预期的功能完全相同,但此页面似乎有错误。
Html表单代码
<form name="devRatingCat" method="post" action="" >
<table class="table table-bordered table-striped" >
<tr>
<th> </th>
<th>ID</th>
<th>Category Name</th>
</tr>
<cfloop query="categories">
<tr>
<td><input class="checkbox" type="checkbox" name="mark" value="#recID#"></td>
<td>#recID#</td>
<td>#categoryname#</td>
</tr>
</cfloop>
</table>
<hr />
<div class="pull-left">
<button class="btn btn-danger" type="button" onClick="dlteCatR(mark);" >Delete</button>
</form>
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方法
<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 = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.recID#">
</cfquery>
</cffunction>
我正在使用firebug来跟踪呼叫,但它并不能很好地解释为什么它不起作用。
此外,当我复制firebug中的链接并在浏览器中自行运行时,事务会像一样发生
$.post()
发送异步请求。如果在该请求完成之前重新加载页面,则该请求将中止。
在您的情况下,在for循环中一次发送n个请求,然后在任何请求都有时间完成之前立即重新加载页面(使用此行window.location.reload();
)。要解决此问题,您可以将它们全部合并为一个$.post
请求并使用success回调,也可以将从$.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();
});
}
}
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 如何使用jQuery自动打开页面上的所有链接
- 如何使用jquery在填充自动完成的值后使文本框只读
- jQuery:循环一个具有不同超时值的循环
- 用程序搜索JQuery数据表中的文本
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jQuery匹配JSON对象的部分文本
- Jquery POST未填充数组
- JQuery使计数器每次更改时都会增加
- 如何在Angular2中使用jQuery插件
- 提高JQuery的性能
- 无法在通过jQuery的ajax加载的页面中执行javascript
- JQuery合并了keyup和focusout两个函数
- 如何使用jQuery选择下拉列表的值
- jQuery not posting - (jQuery - ColdFusion)
- 如何在Jquery Mobile中刷新页面时使用Coldfusion toScript
- ColdFusion built-in AJAX vs JQuery or ExtJS
- 调用Coldfusion组件函数的jQuery-post方法不起作用
- 使用Coldfusion在jquery post请求中使用来自url的函数
- jQuery 将隐藏表单字段发布到 ColdFusion Query