2013-08-12 37 views
1

我在我的速度宏模板之一中使用jQuery(即将加载最后一个的内容页脚)。jQuery脚本必须在ajax调用后运行

此脚本适用于除一页之外的所有页面。在该页面上,页面完全呈现后,将表插入页面中间的。所以我尝试使用onload函数,仍然没有运气。

<table id="ArtifactListTable" class="ItemListTable"> 
<!-- this table is inserted after ajax  request --> 

<script> 
    window.onload = function() { 
    jQuery('.priority1').text('P1'); 
    jQuery('.priority2').text('P2'); 
    jQuery('.priority3').text('P3'); 
    jQuery('.priority4,.priority5').text('None'); 

    jQuery('.priority4,.priority5').addClass('priority0').removeClass('priority4 priority5'); 
    }; 

</script> 

我需要这个AJAX负载功能(我有过阿贾克斯没有控制)后运行我的jQuery。我只能处理我的jQuery。

+0

分享ajax负载如何用于加载表 –

+1

jQuery ajax调用有一个'成功'回调 - 提供一个函数完成上述操作,并将其设置为您的ajax调用的成功回调函数。 – sje397

+0

如果您可以访问由jQuery Ajax调用(http://api.jquery.com/jQuery.ajax/)返回的jqXHR对象,那么您可以附加一个.done()函数,它将在运行后它已经完成(或者如果你想运行它,即使它失败,也使用.always())。 –

回答

0

如果表被使用​​加载,然后利用负载回调下面

$('<someel>').load('url', function(){ 
    jQuery('.priority1').text('P1'); 
    jQuery('.priority2').text('P2'); 
    jQuery('.priority3').text('P3'); 
    jQuery('.priority4,.priority5').text('None'); 

    jQuery('.priority4,.priority5').addClass('priority0').removeClass('priority4 priority5'); 

}) 
+0

感谢您的回复阿伦我alraedy尝试与表的ID加载likejQuery('#ArtifactListTable')。load(function(){ });但不是预期的输出是否有任何我们通过jquery检查以检查任何ajax请求并在ajax调用完成后运行jquery – sathishkumar

0

jQuery的GET或POST给出。成功AJAX调用后调用第三个参数。

$.get("url", {json: "get"}, function(result){ 
    $("#content").html(result); 
    // DO SOME CODE 
}) 
4

如果Ajax调用是由一些插件,它没有做callbacks,你可以使用jQuerys ajaxComplete处理程序,并做取决于请求事情URL

http://api.jquery.com/ajaxComplete/

$(document).ajaxComplete(function(event, XMLHttpRequest, ajaxOptions) { 
    //check XMLHttpRequest and do stuff 
}); 
0
$.ajax({ 
    type: "POST", 
    url: //your URL, 
    contentType: 'application/json; charset=utf-8', 
    dataType: "json", 
    success: function (d) {//pur your script here 
     } 
     }); 
相关问题