首 页ASP视频教程上线| 下载中心教育学院|学习论坛|网站地图
超强快速搜索:
您当前的位置:首页 -> 教育学院 -> 综合教程 -> 综合文章 -> 教育学院->ajax 无刷新提交
   栏 目 导 航
· 综合文章
   站 内 搜 索


  

    阅 读 排 行
· [图文] 如何把下载的漂亮字体...
· ASP视频教程第一章-基...
· ASP字符串函数大全
· [图文] wmv,rm转换flv程序
· asp视频教程第六章 数...
· asp视频教程 第三章 A...
· [图文] iis怎样绑定域名(附图...
· asp视频教程-第二章 创...
· [图文] 火车头采集教程
· DVD解码器的免费获得方...
    相 关 文 章
· [图文] aptana 下载 和ajax开...
· ajax实现用户注册登录...
· php ajax简单应用
· php ajax 实现用户登录...
· php ajax无刷新
· php flv 转化及详细配...
· FCKeditor2.5.1 设置和...
· arp欺骗和防御最简单方...
· php缓存类
· 网站攻击手段

ajax 无刷新提交

第一个是用来无刷新加载一段HTML
第二个是把表单数据转换成一串请求字符串
第三个是结合函数一和函数二的无刷新提交表单实现。

还有一点要提到的是,无刷新表单提交,还不能对文件上传进行处理,这个主要是因为浏览器的安全设置。目前无刷新的上传,一般是用iframe来实现的。关于这个,我们在google里搜索能找到很多

网上虽然已经有很多优秀的ajax的类和函数了,但是或许我这几个函数对大家还有点用处,于是我就发布出来了。
可以在这里下载。


//@desc     load a page(some html) via xmlhttp,and display on a container //@param    url           the url of the page will load,such as "index.php" //@param    request       request string to be sent,such as "action=1&name=surfchen" //@param    method        POST or GET //@param    container           the container object,the loaded page will display in container.innerHTML //@usage //          ajaxLoadPage('index.php','action=1&name=surfchen','POST',document.getElementById('my_home')) //          suppose there is a html element of "my_home" id,such as "<span id='my_home'></span>" //@author   SurfChen <surfchen@gmail.com> //@url     http://www.surfchen.org/ //@license http://www.gnu.org/licenses/gpl.html GPL
if (!window.XMLHttpRequest) {
   window.XMLHttpRequest=function (){
   return new ActiveXObject("Microsoft.XMLHTTP");
   }
}
function ajaxLoadPage(url,request,method,container)
{
 method=method.toUpperCase();
 var loading_msg='Loading...';//the text shows on the container on loading.
 var loader=new XMLHttpRequest;//require Cross-Browser XMLHttpRequest
 if (method=='GET')
 {
  urls=url.split("?");
  if (urls[1]=='' || typeof urls[1]=='undefined')
  {
   url=urls[0]+"?"+request;
  }
  else
  {
   url=urls[0]+"?"+urls[1]+"&"+request;
  }
  
  request=null;//for GET method,loader should send NULL
 }
 loader.open(method,url,true);
 if (method=="POST")
 {
  loader.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 }
 loader.onreadystatechange=function(){
  if (loader.readyState==1)
  {
   container.innerHTML=loading_msg;
   
  }
  if (loader.readyState==4)
  {
   container.innerHTML=loader.responseText;
  }
 }
 loader.send(request);
}
//@desc      transform the elements of a form object and their values into request string( such as "action=1&name=surfchen")
//@param     form_obj            the form object
//@usage     formToRequestString(document.form1)
//@notice    this function can not be used to upload a file.if there is a file input element,the func will take it as a text input.
//           as I know,because of the security,in most of the browsers,we can not upload a file via xmlhttp.
//           a solution is iframe.
//@author    SurfChen <surfchen@gmail.com>
//@url     http://www.surfchen.org/
//@license http://www.gnu.org/licenses/gpl.html GPL
function formToRequestString(form_obj)
{
 var query_string='';
 var and='';
 //alert(form_obj.length);
 for (i=0;i<form_obj.length ;i++ )
 {
  e=form_obj[i];
  if (e.name!='')
  {
   if (e.type=='select-one')
   {
    element_value=e.options[e.selectedIndex].value;
   }
   else if (e.type=='checkbox' || e.type=='radio')
   {
    if (e.checked==false)
    {
     break; 
    }
    element_value=e.value;
   }
   else
   {
    element_value=e.value;
   }
   query_string+=and+e.name+'='+element_value.replace(/\&/g,"%26");
   and="&"
  }
  
 }
 return query_string;
}
//@desc      no refresh submit(ajax) by using ajaxLoadPage and formToRequestString
//@param     form_obj            the form object
//@param     container            the container object,the loaded page will display in container.innerHTML
//@usage     ajaxFormSubmit(document.form1,document.getElementById('my_home'))
//@author    SurfChen <surfchen@gmail.com>
//@url     http://www.surfchen.org/
//@license http://www.gnu.org/licenses/gpl.html GPL
function ajaxFormSubmit(form_obj,container)
{
 ajaxLoadPage(form_obj.getAttributeNode("action").
作者:佚名  来源:不详  发布时间:2008-3-31 21:42:57  发布人:admin
上一篇教育学院:php ajax 实现用户登录
下一篇教育学院:php ajax简单应用
[] [返回上一页] [打 印] [收 藏]

关于本站 - 网站帮助 - 广告合作 - 友情连接
Copyright © 2005-2006 源码教程网 All Rights Reserved 源码教程网,为广大网友提供学习交流.主要提供源码教程下载 ASP源码下载、PHP源码下载、JSP源码下载、CGI源码下载、FLASH源码、C源码、C#源码等程序下载交流
广告联系qq:511411676