Last active
August 29, 2015 14:21
-
-
Save inter-coder/ccffb9ab7c8a4d677ed6 to your computer and use it in GitHub Desktop.
Gather html content from a remote url with JavaScript
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
function xdomain(par){//crossdomain function | |
par.xpath=par.xpath==undefined?"*":par.xpath; | |
par.type=par.type==undefined?"xml":par.type; | |
var xmlhttp=new XMLHttpRequest(); | |
par.url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from html WHERE url="'+par.url+'" AND xpath="'+par.xpath+'"')+'&format='+par.type+'&callback=cb'; | |
xmlhttp.open("GET",par.url,false); | |
xmlhttp.onload=function(){ | |
function cb(d){return d;}//callBack function for returning results from query | |
par.callBack(eval(xmlhttp.responseText)); | |
}; | |
xmlhttp.send(); | |
}; | |
/* example usage | |
xdomain({ | |
url:"http://cropdanka.com/",// url of site | |
type:"xml",//return in xml or JSON format | |
xpath:"*",//filter objects | |
callBack:function(data){ | |
console.log(data);// display object returned from request | |
} | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment