I’m again having some problems with my Random Quote Generator. I changed my HTML,CSS and JS so please tell me where the error is . When I click on the button I get the following error in the console : “XMLHttpRequest cannot load http://quotes.stormconsultancy.co.uk/random.json. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.”
Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>Random Quote Generator</title>
<!-- To ensure compatability with various devices !-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width">
<!-- Including Amatic Google Font -->
<link href='http://fonts.googleapis.com/css?family=Poiret One' rel='stylesheet'>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Various stylesheets used -->
<link rel="stylesheet" href=main.css>
<!-- font-awesome for the heart !-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css">
</head>
<body>
<div class="text-heading text-center container">
Random Quote Generator
</div>
<div class='quote-box' id='qt-box'>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id='author-box'>
Hello
</div>
<br>
<br>
<div class="btn">
<a href="#" id="button">Generate New Quote</a>
</div>
<footer class="footer-text" id="footer">
<div>
Made with <i class="fa fa-heart" aria-hidden='true'></i> by Rahul Baboota
</div>
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!-- Including main.js -->
<script src='main1.js'></script>
</body>
And my JS
//Function which gets the random quotes
var getQuote = function()
{
$.ajax({
url:'http://quotes.stormconsultancy.co.uk/random.json',
datatype: 'jsonp',
type: 'GET',
//If the request is succesful!!
success: function(data)
{
// Adding the quote in the quote box
$('#qt-box').html(data.quote);
// Adding the author name
if (data.author != '')
{
$('#author-box').html(data.author);
}
else
{
$('#author-box').html('Unknown');
}
},
error: function()
{
$('#qt-box').html("There was a problem with the API request");
}
});
};
//Document Ready Function
$(document).ready(function()
{
$('#button').on('click', function(){
getQuote();
})
});