Javascript script for fetching content via AJAX with automatic detection of origin type of AJAX request (Same-Origin + Cross-Origin)