I'm completely new to JavaScript/jQuery, so as a nice "HelloWorld" project I wanted to build a webpage which simply grabs a random Wikipedia article and shows the header and first paragraph. Googling around, it looks like ajax is the way to do this, so I wrote the simple script (with a fixed url for now):
<script>
$(document).ready(function () {
$.ajax({
url: 'https://en.wikipedia.org/wiki/Flemingdon_Park',
type: 'GET',
dataType: "html",
success: function (data)
{
alert('Success!');
$('#MainHeader').html($(data).find('#firstHeader').html());
},
error: function (xmlHttpRequest, textStatus, errorThrown)
{
var serverNotReached = xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0;
if (serverNotReached)
alert("No response from the server!");
else
alert(errorThrown);
}
});
})
</script>
My problem is that I only ever get the "No response from the server" from wikipedia. I tried doing a GET with Postman and the exact same url, and that returned the html as I expected. Next I tried the script with http://stackoverflow.com, but same thing. Finally, I tried http://www.msn.com and that did work. I'm assuming there is something fundamental I am missing here, but I'm not sure what.