在一个形式我有一个模态骨架 - 意味着模态体是空的。 我设计了一些动态添加(用于下拉列表)表单并加载ajax后调用
var scriptname,initiator; $(".launch-add-form").click(function(e){ scriptname=($(this).prop('id')).split("-")[0] ; initiator=$(this).prop('id'); $.ajax({ type:"post", url:"<?=site_url()?>/admin/commoncontroller/getform/", data:{csrftoken:cct,scriptname:scriptname} }).done(function(res){ $("#modalBody").html(res) ;}) });返回与脚本名称匹配的任何脚本,并将响应呈现给模态体。 那么现在从模态我填写表格并保存它正常工作,但问题是在主窗体上有多个下拉菜单,每个都有
.launch-add-form class好吧,如果我用一个下拉保存并尝试使用其他,那么就像几何级数一样调用ajax保存调用...第一个1个呼叫比2个呼叫然后4个呼叫...
有人可以帮忙吗?
In a form I have a modal skeleton--meaning the modal body is empty. I designed number of on the fly add(for dropdowns) form and loading with a ajax post call like
var scriptname,initiator; $(".launch-add-form").click(function(e){ scriptname=($(this).prop('id')).split("-")[0] ; initiator=$(this).prop('id'); $.ajax({ type:"post", url:"<?=site_url()?>/admin/commoncontroller/getform/", data:{csrftoken:cct,scriptname:scriptname} }).done(function(res){ $("#modalBody").html(res) ;}) });Which returns any script that matches the script name and render the response to the modal body. Well now from modal i fill the form and save it which properly works but the problem is on the main form there are multiple drop-downs and each have
.launch-add-form classWell, if I save with one drop down and try to do with other, then the ajax save call is being called like in geometric progression...1st 1 call than 2 calls then 4 calls...
Can anyone help please?
最满意答案
我猜你是多次分配onClick事件。
在添加新事件之前尝试解除任何clic事件的绑定:
$(".launch-add-form").unbind( "click" );所以你的代码将是:
var scriptname,initiator; $(".launch-add-form").unbind( "click" ); $(".launch-add-form").click(function(e){ scriptname=($(this).prop('id')).split("-")[0] ; initiator=$(this).prop('id'); $.ajax({ type:"post", url:"<?=site_url()?>/admin/commoncontroller/getform/", data:{csrftoken:cct,scriptname:scriptname} }).done(function(res){ $("#modalBody").html(res) ;}) });I guess you are assigning the onClick event multiple times.
try unbinding any clic event before adding a new one:
$(".launch-add-form").unbind( "click" );so your code will be:
var scriptname,initiator; $(".launch-add-form").unbind( "click" ); $(".launch-add-form").click(function(e){ scriptname=($(this).prop('id')).split("-")[0] ; initiator=$(this).prop('id'); $.ajax({ type:"post", url:"<?=site_url()?>/admin/commoncontroller/getform/", data:{csrftoken:cct,scriptname:scriptname} }).done(function(res){ $("#modalBody").html(res) ;}) });更多推荐
发布评论