8
Hello a while ago I asked this question:
Grab content from another page by javascript or jquery
Fellow @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>
<!-- Scripts Javascript -->
<script type="text/javascript" src="http://projetos.lucaspeperaio.com.br/ajax-cross-domain/jquery.xdomainajax.js"></script>
<title>jQuery e Ajax Cross Domain</title>
</head>
<body>
<input type="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 content from Omain. But it does not work for all types of protocol.
If you have an http site it works properly, but if you have an https site it will not work. (If it is in an http protocol it takes http content but if it is in an https it gives error.)
I’m willing to implement this function on the site: https://ebookstore.xtechcommerce.com/acessorios
and he makes the following mistake:
Example with https protocol:
I switched the protocol and it worked, but it has to work on both protocols (because it will be an API).
Example with http protocol:
I came to the conclusion with this error that the protocol should be http to work on the site. But since I’m making an API the script doesn’t have to only call the two protocols, it also has to work on the two protocols.
Can someone help me?
There are some similar questions, but you don’t just need to take cross-Omain content, it needs to work in both types of protocols. It has to work for both http and https.
Load and read XML via AJAX Cross-Domain
Ajax cross-Omain request with pure Javascript (no Apis)
For this it would not be feasible to change the protocol to http.
I was thinking maybe use an if, if it’s http it uses a domain to cross if it’s https it uses another.
But I may have a more practical solution.
Help me ^~
I recently solved a problem similar to a Jason give in a domain without headers, as I had access to the api that listed the json I just did a php q copy the content of the url of that json and save in a json inside my Server, and so I could read everything without problem. I did a Cron task on the Server that ran the php copy script every 1 hour keeping my json up to date. Sometimes it’s an output.
– Fábio Duarte
Congratulations to the others who also arrived at the same solution, but I decided first :P
– SneepS NinjA
I will check the answers one by one and reward who gave the best solution. Thank you
– Felipe Jorge
already checked if there is an error with output: //projects.lucaspeperaio.com.br/ajax-cross-Domain/jquery.xdomainajax.js
– Ivan Ferrer