I have an MVC application, and on one of my pages I am using jQuery .get() to go out to our company's Wordpress site and retrieve information to be posted on my view page. This works in IE 11, but does not in Chrome or Edge.
Here is my script:
<script>
$.get("https://ourcompany.com/feed/", function (data) {
var $XML = $(data);
$XML.find("item").each(function (index) {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
pubDate: $this.find("pubDate").text(),
author: $this.find("author").text(),
};
if (index == 0)
$('#Feed').append($('<h4/>').addClass('header').text(item.title));
else
$('#Feed').append($('<h4/>').addClass('following-headers').addClass('header').text(item.title));
$('#Feed').append($('<a target="_blank" href="' + item.link + '"/>').text("Get the full story here!"));
if (index >= 2)
$('#Feed').append($('<p/>').css({ "margin-top": "10px" }).text("Published on " + item.pubDate.split("+")[0]));
else
$('#Feed').append($('<p/>').css({ "margin-top": "10px" }).addClass('lastParagraph').text("Published on: " + item.pubDate.split("+")[0]));
if (index >= 2)
return false;
});
});
</script>
I have published my MVC project to our company's webserver, and when I open up the page that is running this script.. I check the console in Chrome and see this:
Failed to load https://ourcompany.com/feed/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ourwebserver' is therefore not allowed access.
How is this working in IE and not Chrome and Edge? How do I get this to work in Chrome and Edge?
This is not a duplicate because I am not using Postman.. and I was able to resolve this issue by installing a plugin for my wordpress site.