Random quote machine http to https
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$.getJSON("https://crossorigin.me/http://quotes.stormconsultancy.co.uk/random.json",function(data) { | |
$("#quote").text(data.quote); | |
$("#author").html(data.author); | |
$("#tweet_this").attr('href', 'http://www.twitter.com/intent/tweet?text=' + data.quote + ' -- ' + data.author); | |
}); | |
}); | |
$("#get_quote").click(function(){ | |
$.getJSON("https://crossorigin.me/http://quotes.stormconsultancy.co.uk/random.json",function(data) { | |
$("#quote").text(data.quote); | |
$("#author").html(data.author); | |
$("#tweet_this").attr('href', 'http://www.twitter.com/intent/tweet?text=' + data.quote + ' -- ' + data.author); | |
}); | |
}); |
@TylerMoeller I tried a similar solution for code duplication, however doing it this way it doesn't loads the quote automatically when someone opens/refreshes the page. Also, https://crossorigin.me/
doesn't work in both of the versions codes in my system. If it works in yours then , I don't know what is going on.
My system has the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://crossorigin.me/http://quotes.stormconsultancy.co.uk/random.json. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
I will update here if anything works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To avoid code duplication and using the proxy when it isn't needed, you can do:
Edit: Also, you'll want to encode your Twitter text, or tweets will get cut off at punctuation.