获取HTML code。使用JavaScript的一个网址 [英] get html code using javascript with a url

查看:244
本文介绍了获取HTML code。使用JavaScript的一个网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用xmlhtt prequest的URL得到HTML源$ C ​​$ C。是否有任何人谁可以帮助我?我是新来编程,我也不太清楚我该怎么做没有jQuery的。先谢谢了。

I am trying to get the source code of html by using a xmlhttprequest with a url. Is there anyone who can help me with this? I am new to programming and I am not too sure how can I do it without jQuery. Thanks in advance.

推荐答案

使用jQuery

$.ajax({ url: 'your-url', success: function(data) { alert(data); } });

数据是你的HTML

data is your html

没有的jQuery

function makeHttpObject() {
  try {return new XMLHttpRequest();}
  catch (error) {}
  try {return new ActiveXObject("Msxml2.XMLHTTP");}
  catch (error) {}
  try {return new ActiveXObject("Microsoft.XMLHTTP");}
  catch (error) {}

  throw new Error("Could not create HTTP request object.");
}
var request = makeHttpObject();
request.open("GET", "your_url", true);
request.send(null);
request.onreadystatechange = function() {
  if (request.readyState == 4)
    alert(request.responseText);
};

这篇关于获取HTML code。使用JavaScript的一个网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆