function GetInf() {
var code = $("#code0").val();//参数
var xmlHttp;
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("GET", "http://119.145.12.180/anta/Service/GetFlowcodeInfo?flowcode=" + code, true);
var str = xmlHttp.responseText;//提取不出东西,为空
var a = unescape(xmlHttp.responseText);//提取不出东西,为空
xmlHttp.send(null);
}
我想问我这个哪里错了,为什么我提不出东西。
有谁有好的办法用ajax或者jquery抓取远程网页的内容。
我使用的语言是asp.netxmlhttprequestasp.netjqueryajax
var code = $("#code0").val();//参数
var xmlHttp;
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("GET", "http://119.145.12.180/anta/Service/GetFlowcodeInfo?flowcode=" + code, true);
var str = xmlHttp.responseText;//提取不出东西,为空
var a = unescape(xmlHttp.responseText);//提取不出东西,为空
xmlHttp.send(null);
}
我想问我这个哪里错了,为什么我提不出东西。
有谁有好的办法用ajax或者jquery抓取远程网页的内容。
我使用的语言是asp.netxmlhttprequestasp.netjqueryajax
你可以先把远程文件下载到本地,然后再用jquery进行加载。
Making cross domain JavaScript requests using XMLHttpRequest or XDomainRequest
http://www.leggetter.co.uk/2010/03/12/making-cross-domain-javascript-requests-using-xmlhttprequest-or-xdomainrequest.html
<head>
<title>Ajax Sample</title>
<script type="text/javascript">
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
function makerequest(serverPage,objId)
{
var obj = document.getElementById(objId);
xmlHttp.open("GET", serverPage);
xmlHttp.onreadystatechange = function()
{
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
obj.innerHTML = xmlHttp.responseText;
}
}
xmlHttp.send(null);
}
</script>
<body onLoad="makerequest ('content1.html','hw')">
<div align="center">
<h1>My Webpage</h1>
<a href="content1.html" onClick="makerequest('content1.html','hw'); return false;">Page 1</a>
<a href="content2.html" onClick="makerequest('content2.html','hw'); return false;">Page 2</a>
<a href="content3.html" onClick="makerequest('content3.html','hw'); return false;">Page 3</a>
<a href="content4.html" onClick="makerequest('content4.html','hw'); return false;">Page 4</a>
//这里就是将要替换content1~4.html的位置。
<div id="hw"></div>
</div>
</body>
</html>
不能跨域的,别费这个心了。
有研究跨域的时间 还不如写个后台抓取页面 保存到本地 然后再用jquery解析。
深入浅出JSONP--解决ajax跨域问题
这个能返回网页吗?dataType只能指定dataType:"jsonp"