Hello some time ago I asked this question:
Paste content of another page by javascript or jquery
The colleague @SneepSNinjA made the following algorithm that worked.
$(document).ready(function(){
$("button").click(function(){
site = $("#site").val();
$.ajax({
url: site,
type: 'GET',
success: function(res) {
var headline = $(res.responseText).text();
$("#conteudo").html(headline);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><head><!--ScriptsJavascript--><scripttype="text/javascript" src="http://projetos.lucaspeperaio.com.br/ajax-cross-domain/jquery.xdomainajax.js"></script><title>jQueryeAjaxCrossDomain</title></head><body><inputtype="text" id="site" value="http://" />
<button id="acessar">Clique para obter o conteúdo deste site</button>
<div id="conteudo" style="background:#EEF0A6"></div>
</body>
</html>
However, there is a problem. This code takes cross domain content. But it does not work for all protocol types.
If you have an http site it works correctly, however if you have an https site it will not work. (If it is in an http protocol it will get http content but if it is in an https it gives an error.)
I want to implement this function in the site: link
and it gives the following error:
Example with https protocol:
Ichangedtheprotocolanditworked,butithastoworkonbothprotocols(Wellit'sgoingtobeanAPI).
Examplewithhttp:protocol
I came to the conclusion with this error that the protocol should be http to work on the site. But since I am making an API the script does not have to just call the two protocols, it also has to work in both protocols.
Can anyone help me?
There are some similar issues, but you do not just need to get cross domain content, it needs to work on both types of protocols. It has to work for both http and https.
Load and read XML via AJAX Cross-Domain
Requisition Ajax cross-domain with pure Javascript (without APIs)
This is why it would not be feasible to change the protocol to http.
I was thinking of maybe using an if, if it is http it uses one domain to cross if it is https it uses another.
But perhaps you have a more practical solution.
Help me out ~ ~