获取HTML code。使用JavaScript的一个网址

编程入门 行业动态 更新时间:2024-10-16 02:24:35
本文介绍了获取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的一个网址

本文发布于:2023-11-28 16:00:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   HTML   code   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!