PHP 利用AJAX获取网页并输出(原创自Zjmainstay)
2012-08-06 10:00
489 查看
看点:
1、file_get_contents超时控制。
2、页面编码判断。
3、键盘Enter键捕捉响应。
4、键盘event兼容处理。//event = event || window.event;
5、XMLHttpRequest 和 jQuery 两种实现方案。
6、页面及源码同时展示。
jQuery 版本 get_web.php
1、file_get_contents超时控制。
2、页面编码判断。
3、键盘Enter键捕捉响应。
4、键盘event兼容处理。//event = event || window.event;
5、XMLHttpRequest 和 jQuery 两种实现方案。
6、页面及源码同时展示。
jQuery 版本 get_web.php
<?php header("Content-type: text/html; charset=utf-8"); if(!empty($_POST['input_text'])) { ini_set('default_socket_timeout', 10); if(!$data = file_get_contents($_POST['input_text'])) { echo "Time out!"; return ; } $charset_pos = stripos($data,'charset'); if($charset_pos) { if(stripos($data,'utf-8',$charset_pos)) { echo iconv('utf-8','utf-8',$data); }else if(stripos($data,'gb2312',$charset_pos)) { echo iconv('gb2312','utf-8',$data); }else if(stripos($data,'gbk',$charset_pos)) { echo iconv('gbk','utf-8',$data); } return; } echo $data; }else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Get Web Page</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="zh-CN" /> <script type="text/javascript" src="http://files.cnblogs.com/Zjmainstay/jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(document).keyup(function(e){ e = e || window.event; if(e.keyCode == 13 && $("#input_text").val() != '') { $(".button_box").click(); } }); $(".button_box").click(function(){ if($("#input_text").val() == '') { $("#input_text").addClass('errorTips').focus(); return false; }else { $("#input_text").removeClass('errorTips'); } $.ajax({ url: '<?php echo $_SERVER['PHP_SELF'] ?>', data: 'input_text='+$("#input_text").val(), type:'POST', success:function(msg){ $(".html_tips").show(); $("#origin_website").attr('href',$("#input_text").val()); $("#back_a").attr('href',document.location.href); $("#click_show").show(); $("#output_page_html").empty().val(msg).css({height:parseInt($(document).height()-100)}).show(); $("#output_page").empty().html(msg).show(); } }); }); }); </script> <style> .div_box{ margin-top:10px; } .input_box{ border:1px solid; margin-left:10px; margin-top:2px; height:15px; float:left; size:32 font-size: 14px; } .button_box{ float:left; height:23px; padding-bottom:3px; } .hide_box{ display:none; } .a_box{ margin-left:10px; margin-top:3px; height:15px; float:left; font-size: 14px; } .clear_box{ height:50px; } .error_tips{ border:1px solid red; } #output_page_html{ width:960px; margin:0 auto; } .html_tips{ float: left; margin: 0 21px; font-size:1.8em; } </style> </head> <body> <div class="div_box"> <input id="input_text" class="input_box" type="text" value=""></input> <input type="button" class="button_box" value="Get it!" ></input> <div id="click_show" class="hide_box"> <a id="origin_website" class="a_box" href="#" target="_black">访问原站</a> <a id="back_a" class="a_box" href="#">后退</a> </div> </div> <div class="clear_box"></div> <div class="html_tips hide_box">站点</div> <div id="output_page"></div> <div class="html_tips hide_box">站点源码</div> <textarea id="output_page_html" class="hide_box"></textarea> </body> </html> <?php } //End_php
相关文章推荐
- PHP 利用AJAX获取网页并输出的实现代码(Zjmainstay)
- PHP 利用AJAX获取网页并输出的实现代码(Zjmainstay)
- 利用ajax获取到的网页源码不能执行js代码
- 利用js将ajax获取到的后台数据动态加载至网页中的方法
- 利用js将ajax获取到的后台数据动态加载至网页中
- php利用curl获取网页title内容
- [原创]利用爬虫技术获取网页数据,以及想要的指定数据
- 利用PHP获取网页的源代码或标题
- 利用PHP获取网页的源代码或标题
- 利用js将ajax获取到的后台数据动态加载至网页中
- 同一域名对应多个IP时,PHP获取远程网页内容的函数[原创]
- ajax利用FormData、FileReader实现多文件上传php获取
- [PHP][Class]利用DOMDocument获取XML内容[已验证][原创]
- jquery的$.ajax()利用FormData数据类型与php后台交互
- 转:php获取网页内容方法总结
- 利用php实现:当获取的网址不是特定网址时候跳转到指定地址
- asp.net中利用ajax获取动态创建表中文本框的值
- AJAX 跨域请求 - JSONP获取JSON数据(PHP版)
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例 [原创]
- 利用php获取服务器时间的实现代码