我有問題的ajax請求和簡單的<input type="submit"/>
。jQuery live不按預期方式工作
我用它來加載其他視圖,模塊化的意思,與jQuery使用.load(url)
從一個視圖到另一個視圖。 所以問題是,如果我加載view_1裏面view_1和js腳本view_2裏面view_1我需要使用live('click')
例如從view_2啓動一個xhr請求,所以當我嘗試啓動3 (multiple) xhr at same time
,而不是在1時間,不知道爲什麼。
我唯一知道的是:
- 使用
live('click')
在view_1它推出3多XHR。 - 使用
click()
in view_1它不起作用(顯然我認爲)。 - 使用
click()
裏面直接view_2它工作(但我不能使用加載JS意見 ,我可以用js只能在「父母」的觀點)
功能也很簡單,真的沒有知道爲什麼我有這個問題(我也禁用提交在ajax beforeSend)檢查這是一個View_1代碼運行在加載view_2,並啓動3 XHR的點擊:|
$(document).ready(function(){
$('#save-doc').live('click',function(){
var _title = $('#doc-title').val();
var _doc = $('#doc-doc').val();
update_doc(url_update_doc,{'title':_title,'doc':_doc,'id_doc':_choosed_doc,'id_project':id_project},this);
});
});
function update_doc(_url,_data,_starter){
$.ajax({
type:'POST',
data:_data,
url:_url,
dataType:'json',
beforeSend:function(){
$('.ajax-loading').show();
$(_starter).attr('disabled','disabled');
},
error:function(){
$('.ajax-loading').hide();
$(_starter).removeAttr('disabled');
},
success:function(json){
$('.ajax-loading').hide();
$(_starter).removeAttr('disabled');
if(json.error){
$('#error-title').html(json.error_title);
$('#error-doc').html(json.error_doc);
$.scrollTo('.append-form-edit-doc','fast');
}
if(json.confirm){
$.scrollTo('#top','fast');
$.gritter.add({
title:'Document Saved',
text:json.confirm
});
}
}
});
}
任何機會你有多個ID爲'save-doc'的元素? –
您嘗試添加「返回false」嗎?到「點擊」處理程序的末尾? – Pointy
@Shadow Wizard nope id是id :) .. – sbaaaang