[英]HTML Javascript webpage content reading into a var
Lets say I have this weblink: http://checkip.amazonaws.com/ . 可以说我有这个网站链接: http ://checkip.amazonaws.com/。 I've made a java program (actual program. not webpage) that reads the content of this webpage (eg. "25.25.25.25") and displays it in a
jLabel
(Using Netbeans IDE 1.7.3) and it works. 我已经制作了一个Java程序(实际程序。不是网页)来读取该网页的内容(例如“ 25.25.25.25”),并将其显示在
jLabel
(使用Netbeans IDE 1.7.3),并且可以正常工作。
Now how can I read the contents of this same webpage (eg. "25.25.25.25") and display it as normal text on a webpage (The final webpage must be .html not .php or what ever)? 现在,我如何才能读取同一网页(例如“ 25.25.25.25”)的内容,并将其显示为网页上的普通文本(最终网页必须是.html而不是.php或其他)?
I dont mind any script whether is html or javascript or anything, I just please need it to work so that when the webpage is opened it can read something like: 我不在乎任何脚本,无论是html还是javascript或其他任何东西,我只需要它可以工作,这样在打开网页时它可以读取如下内容:
"Your IP: 25.25.25.25" “您的IP:25.25.25.25”
Preferably reading the contents of http://checkip.amazonaws.com/ into 最好将http://checkip.amazonaws.com/的内容读入
<script>var ip = needCodeHere</script>
If I can get the IP into a var or read the contents of that webpage into a var I'm happy but other code is happy to as long as it works. 如果我可以将IP放入var或将该网页的内容读取到var中,那么我很高兴,但只要它能正常工作,其他代码也很满意。
Please help :( been staring at google for days and cant find a solution) 请帮助:(盯着谷歌好几天了,找不到解决方法)
You'll need 3 files (in the same directory) to do that. 为此,您需要3个文件(在同一目录中)。 A HTML file to show the ip, a PHP file to get that ip via curl, and a JS file to connect the html and the php.
一个用于显示ip的HTML文件,一个用于通过curl获取该ip的PHP文件,以及一个用于连接html和php的JS文件。 It would be simpler if the "final webpage" could be the ip.php itself, but let's do it this way:
如果“最终网页”可以是ip.php本身,那会更简单,但是让我们这样做:
1) ip.html (the "final webpage") 1)ip.html(“最终网页”)
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="ip.js"></script>
<div id="ip"></div>
2) ip.php 2)ip.php
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://checkip.amazonaws.com');
$result = curl_exec($curl);
curl_close($curl);
?>
3) ip.js 3)ip.js
$.ajax({
url: 'ip.php',
type: "GET",
success: function (data) {
$('#ip').html("Your IP: " + data);
}
});
Let me know if you need more explanation. 让我知道是否需要更多说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.