0

I'm caching a number a links in a database via a page crawler that makes ajax calls with jQuery. Before making an ajax call to a remote site, I make sure the link address has one of a list of domains or has one of two file extensions:

var j = jQuery.noConflict();

...

var substrings = ['site1',
                  'site2',
                  'site3',
                  'site4'];
var length = substrings.length;
console.log(length);
$.each(the_links, function(i, el){
  var dl_link = this;
  if (dl_link.endsWith('.html') || dl_link.endsWith('.php') || dl_link.indexOf(substrings[length])!=-1) {
    j.get( 'https://example.com/insert.php', { title:post_title, link: dl_link } )
        .done(function( data ) {
          console.log('response:');
          afterInsert(data);
        });
  }
  length--;
  if(link_count == 0){
    console.log('inserted all links');
  }
});

When I run the script, my ajax calls run without issues and my records are created in the database, but nothing is returned to the browser console in the ajax callback:

Browser terminal output

How can I access the contents of my ajax response?

I also tried the following ajax call and I'm still not able to log the response in my console, even though it appears in the Response tab of the XHR entry in the console:

j.get(insert_script, { title: post_title,link: dl_link}, function(data, textStatus, jqXHR) {
   console.log('response:'); 
   afterInsert(data);
});
Keyslinger
  • 4,903
  • 7
  • 42
  • 50
  • What is the `j` in `j.get` exactly? A different version of jQuery or something? – Wesley Smith Nov 23 '19 at 01:48
  • @DelightedD0D I have jQuery running in no-conflict mode because the page I'm caching is running on a remote host with a different version of jQuery. Thus I use the following `var j = jQuery.noConflict();` – Keyslinger Nov 23 '19 at 01:50
  • Hmm, perhaps that version of jquery doesnt dig the `.done`, what happens if you try `$.get('https://djpanaflex.com/custom/cache/insert.php', { title: post_title,link: dl_link}, function(data, textStatus, jqXHR) { console.log('response:'); afterInsert(data);});` – Wesley Smith Nov 23 '19 at 01:54

1 Answers1

0

It turns out my ajax response wasn't being provided to the console because of CORS. I was able to get around this using the CORS Everywhere add-on for Firefox

Keyslinger
  • 4,903
  • 7
  • 42
  • 50