2012-11-01 39 views
0

我正在运行一个post函数,然后函数结束。我正在运行另一个功能。问题是第二个功能不起作用,如果我没有在功能的警报消息,它不运行...如果警报被注释掉,jquery功能不能正常工作

jQuery的功能是:

function applyeditable(){ 
    //alert('trying to apply editable class...'); 

$(".edit_mystatus").editable('/cgi-bin/my_cgi_script.pl', { 
event  : 'dblclick',  //or dblclick 
data  : " {'A':'Active','C':'Completed','D':'Deleted'}", 
type  : 'select', 
submit  : 'Ok', 
indicator : '<img src="http://my_website/images/indicator.gif">', 
placeholder : 'Double Click to Edit', 
tooltip  : 'Double Click to edit...', 
style  : 'display: inline', 
name  : 'name', 
id   : 'id', 
callback : function(value, settings) { 
       // console.log(this); 
       // console.log('returned value= '+value+' we have to now disable rest of form if Completed or Deleted'); 
       // console.log(settings); 
       } 
}); 
$(".edit_mynotes").editable('/cgi-bin/my_cgi_script.pl', { 
    event  : 'dblclick',  //or dblclick 
    type  : 'textarea', 
    rows  : 10, 
    cols  : 100, 
    cancel  : 'Cancel', 
    submit  : 'Save', 
    indicator : '<img src="http://my_website/images/indicator.gif">', 
    placeholder : 'Double Click to enter text', 
    tooltip  : 'Double Click to edit...', 
    style  : 'display: inline', 
    name  : 'name', 
    id   : 'id' 
}); 
$(".ajaxfileupload").editable('/cgi-bin/my_cgi_script.pl', { 
    type  : 'ajaxupload', 
    submit  : 'Upload', 
    cancel  : 'Cancel', 
    indicator : '<img src="http://my_website/images/indicator.gif">', 
    tooltip  : "Double Click to upload...", 
    style  : 'display: inline', 
    name  : 'filename', 
    id   : 'id' 
}); 

$(".checkclass").click(function() { 
    var $this = $(this); 
    // $this will contain a reference to the checkbox 
    var chkboxval = $this.val(); 
    if ($this.is(':checked')) { 
     alert('the checkbox was checked val='+chkboxval); 
    } else { 
     alert('the checkbox was UNchecked val='+chkboxval); 
    } 
}); 
} 

HTML是:

<input type="checkbox" class="checkclass" value="1_0"> 
<input type="checkbox" class="checkclass" value="1_1"> 
<input type="checkbox" class="checkclass" value="1_2"> 

...

+0

欢迎的奇妙世界** **异步!你不能那样做。 – SLaks

+0

它可能工作得很好,你只是遇到异步的意思, – adeneo

+0

当警报被解雇..它只是给了一些时间来完成请求..这是你觉得它有效的唯一原因当有一个警报 –

回答

0

可应用的函数必须从调用函数的最内层'on success'事件中调用。这将处理事物的异步性。

例如:

callingfunction(ABC){ ... ...

$.get(data, function(myfile) { 
$("#someid").html(myfile); 
applyeditable()  //this call runs after above is success (100% execution) 
}); 

... }