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:
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);
});
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