I use crossdomain ajax to get entire html page code ,but it always respone a failed massage.
consolelog: " Uncaught SyntaxError: Unexpected token < "
This is my ajax function.
function t(){
var url = document.getElementById("url").value;
$.ajax({
url: 'https://www.google.com/',
type: 'GET',
crossDomain: true,
data:'',
dataType: 'jsonp',
success: function() { alert("Success"); },
error: function() { alert('Failed!'); },
});
}
PS. I don't want to use "Access-Control-Allow-Origin" method to solved this problem.
anyone have any answer plz tell me,thx a lots
!!Update!!
I use proxy to solved this problem.
first you must create a proxy file, I use php to be a example.
proxy.php
<?php
$url ='https://www.google.com/searchbyimage?site=search&sa=X&image_url=http://kingofwallpapers.com/apple/apple-015.jpg';
if($_GET['uri']=='')
echo file_get_contents($url);
else
echo file_get_contents($_GET['uri']);
?>
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
</head>
<script type="text/javascript">
//var NewArray = data.toString().split("=");
function t(){
$.get("proxy.php?uri=", function(data) {
alert(data);
x(data);
});
}
function x(data){
$.get("proxy.php?uri="+data.toString().split('"')[5], function(data2) {
alert("Data Loaded: " + data2);
});
}
</script>
<body onload="t()">
</body>
</html>
it's seems work!! But I get a new problem.It's seems error from google server. I can't use ajax to visit google imagesearch, it's will response a 403error or 302 moved.
PS.Maybe I need a google API or any code I lost to add?
thx everyone : )
</div>