2011-11-08 2 views
2

jQuery에서 getJSON 함수를 재정의하여 추가 매개 변수를 제공 한 다음 원래 getJSON을 호출하려고합니다. 나는 JavaScript에 익숙하지 않고 다른 유사한 예제와 함께이 글을 긁어 모았습니다. 필자가 본 대부분의 예제는 jQuery.fn 네임 스페이스의 함수에서 동작을 재정의합니다. 누군가 내가 잘못하고있는 것을 말해줌으로써 나를 도울 수 있습니까?javascript - getJSON에서 jQuery Core 함수 재정의

<html> 
<head> 
<script type="text/javascript" src="./js/jquery-1.6.4.min.js"></script> 
<script type="text/javascript"> 

(function($){  
    var _old = $.getJSON; 
    $.getJSON = function(){ 
     alert("Calling overridden getJSON");  
     return _old.apply(this,arguments); 
    }; 
})(jQuery); 

$(document).ready(function() { 
    try { 
     $(this).getJSON('ajax/test.json', function(data) { 
      var items = []; 
      alert('done'); 
     }); 
    } 
    catch (err) 
    { 
     alert(err.message); 
    } 
}); 
</script> 
</head> 
<body> 
</body> 
</html> 

답변

1

당신은 $.getJSON하지 $(foo).getJSON를 호출 할 필요가;

$.getJSON('ajax/test.json', function(data) { 
    var items = []; 
    alert('done'); 
}); 
+0

넵. 고맙습니다. – Geoff