장고를 기반으로하는 웹 응용 프로그램이 있습니다. Scrapy Crawler을 사용하여 웹 페이지를 크롤링합니다. 내 목표는 현재 jQuery 및 AJAX 요청을 사용하여 웹 페이지 내에서 크롤러를 제어 할 수 있도록하는 것입니다. 웹 페이지에이 ReferenceError를 해결하는 방법은 무엇입니까?
- , 나는 버튼이 있습니다
내 이론 설정은 다음과 같다. 버튼을 클릭하면 크롤러가 서버 측에서 시작됩니다.
- 일단 크롤러가 시작되면 지금까지 크롤링 된 웹 페이지 수를 확인하기 위해
window.setInterval
을 사용하여 AJAX GET 요청을 서버에 주기적으로 보냅니다. - 일단 크롤러가 끝나면
window.clearInterval
을 사용하여 GET 요청을 중지해야합니다.$(document).ready(function() { // This variable will hold the ID returned by setInterval var monitorCrawlerId; $startCrawlerButton.on('click', function(event) { // This function should be run periodically using setInterval var monitorCrawler = function() { $.ajax({ type: 'GET', url: '/monitor_crawler/', // ... success: function(response) { // if the server sends the message that the crawler // has stopped, use clearInterval to stop executing this function if (response.crawler_status == 'finished') { clearInterval(monitorCrawlerId); } } }); }; // Here I send an AJAX POST request to the server to start the crawler $.ajax({ type: 'POST', url: '/start_crawler/', // ... success: function(response) { // If the form that the button belongs to validates correctly, // call setInterval with the function monitorCrawler defined above if (response.validation_status == 'success') { monitorCrawlerId = setInterval('monitorCrawler()', 10000); } } }); }); });
문제 : 나는이 코드를 실행하면, 나는 파이어 폭스의 웹 콘솔이 얻을 :
ReferenceError: monitorCrawler is not defined
이 내 현재 코드에서 해당 라인이다 그러나 이상한 것은 함수 monitorCrawler
이 주기적으로 어쨌든 실행된다는 것입니다. 그러나 매번 실행될 때마다 동일한 오류 메시지가 다시 나타납니다. 을 $startCrawlerButton.on()
외부에 넣어도 여전히 동일한 오류가 발생합니다. 이 문제를 어떻게 해결할 수 있습니까? 내가 JavaScript 초보자이기 때문에, 어떤 도움을 주셔서 감사합니다. 고마워요!
고마워, 이고르. :) 이것은 내가 필요한 것입니다. 이런 식으로, 나는 필자의 경우에 필요한'monitorCrawler()'에 매개 변수를 추가 할 수있다. 당신이이 특별한 해결책을 게시 한 첫 번째 사람 이었기 때문에 당신의 대답을 받아들입니다. – pemistahl