Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resolve this ReferenceError?
    primarykey
    data
    text
    <p>I have a web application based on Django. I use the <a href="http://scrapy.org/" rel="nofollow">Scrapy Crawler</a> to crawl webpages. My goal, at the moment, is to be able to control the crawler from within a webpage using jQuery and AJAX requests.</p> <p>My theoretical setup is the following:</p> <ul> <li>On the webpage, I have a button. When I click the button, the crawler is started on the server-side.</li> <li>Once the crawler has started, I periodically send AJAX GET requests to the server using <a href="https://developer.mozilla.org/en-US/docs/DOM/window.setInterval" rel="nofollow"><code>window.setInterval</code></a> to find out how many webpages have been crawled so far.</li> <li>Once the crawler has finished, the GET requests should stop by using <a href="https://developer.mozilla.org/en-US/docs/DOM/window.clearInterval" rel="nofollow"><code>window.clearInterval</code></a>.</li> </ul> <p>These are the relevant lines from my current code:</p> <pre><code>$(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); } } }); }); }); </code></pre> <p><strong>The problem:</strong> When I execute this code, I get this in Firefox's web console: </p> <pre><code>ReferenceError: monitorCrawler is not defined </code></pre> <p>The strange thing, however, is that the function <code>monitorCrawler</code> gets periodically executed anyway. But with every execution, I get the same error message again. If I put <code>monitorCrawler</code> outside of <code>$startCrawlerButton.on()</code> I still get the same errors. How can I resolve this? Since I'm a JavaScript newbie, any help is appreciated. Thank you very much! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload