2012-06-15 107 views
1

我看到一堆类似的问题,但没有找到我需要的答案。我有这样的功能:从文档准备jquery调用函数

function fnGetContent(keyword) { 
    var NewKeyword = keyword.tag; 
    var type = keyword.type; 
    $.ajax({ 
     type: "POST", //GetEvents(iType As Integer, sSearch As String) 
     url: "Default.aspx/GetEvents", 
     data: "{'iType':'"+ type +"','sSearch' : '" + NewKeyword + "'}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (msg) { 
      var res = unescape(msg.d); 
      $("#divResults").html(res); 
      $('.accordian_body').hide(); 
      $('.accordian_head').click(function() { 
       $(this).next().animate(
        { 'height': 'toggle' }, 'fast' 
       ); 
       $('.plus', this).toggleClass('subtract'); 
       $('#<%= tSearch.ClientID %>').val() = 'Search by event, team, artist or venue'; 
      });  
     } 
    }); 
    return false; 
} 

正常工作正在从这里称为:

<a href="javascript:void(0)" onclick="fnGetContent({'type' : '2', 'tag' : 'concert'});">TEST TAG</a> 

但我也想呼吁我Document.Ready这个功能,我想它的权利运行时的页面加载,那么每次我想通过<a href>更新结果时,我都会打电话给他。这不工作,其他的答案类似的问题是不调用定义出来的准备方面的功能,我知道这是可以调用从多点同样的功能包括的document.ready

$(document).ready(function() { 
    function fnGetContent("{'type' : '2' , 'tag' : ' ' }"); 
}); 

回答

1

如果任何人遇到这个问题,我想通了,不写功能,并且不带引号

$(document).ready(function() { 
    fnGetContent({'type' : '1' , 'tag' : ' ' }); 
}); 
+0

是的,当你调用函数时,当然不是'function'关键字。我没有找到多个错误... – Guffa

4

删除引号,让你在一个对象传递给函数,而不是一个字符串:

function fnGetContent({'type' : '2' , 'tag' : ' ' }); 
+0

那仍然不起作用 –