<% Response.Charset="gb2312" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script>
//@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
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
var loader = new ActiveXObject("Microsoft.XMLHTTP");
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')
{
elementvalue=e.options[e.selectedIndex].value;
}
else if (e.type=='checkbox' || e.type=='radio')
{
if (e.checked==false)
{
break;
}
elementvalue=e.value;
}
else
{
elementvalue=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").value,formToRequestString(form_obj),form_obj.method,container)
}
</script>
<body>
<form name="form1" method="post" action="bbb.asp" >
<p>
<input type="text" name="t1">
</p>
<p>
<input type="text" name="t2">
</p>
<p>
</p>
</form>
<a href=# onclick="javascript:ajaxFormSubmit(document.form1,document.getElementById('my_home'))">aa</a>
<span id='my_home'></span>
</body>
</html>
<% Response.Charset="gb2312" %>
bbb你好<%=request("t1") %>+<%=request("t2") %>
-------------
另附第一个函数使用方法
<a href=# onclick="javascript:ajaxLoadPage('aaa.asp','action=1&name=surfchen','POST',document.getElementById('my_home')) ">aa</a>
<span id='my_home'></span>
--------
//下面两行使浏览器不会在本地缓存结果
Response.setHeader(“Cache-Control”,”no-cache”);
Response.setHeader(“Pragma”,”no-cache”);
分享到:
相关推荐
简单的ajaxt无刷新实现表单提交的实例(myeclipse 直接导入运行) 学习点: 1;ajax无刷新表单提交 2;ajax的运行历程 最简单明了的实例,清晰的帮你弄清上述概念,运行简单,只需解压该包,然后Myeclipse中file - ...
php无刷新提交表单
NULL 博文链接:https://sorehead.iteye.com/blog/283680
用iframe提交表单,主要是将表单提交到iframe中,可实现无刷新提交。 html页面: <iframe name="FORMSUBMIT" width="1" height="1" ></iframe> ...
使用mvc无刷新提交,提交后会及时更新数据
ajax表单验证,无刷新提交表单,并发送邮件通知
弹DIV提交表单无刷新
html5 canvas点击刷新验证码提交表单 html5 canvas点击刷新验证码提交表单
主要介绍了不使用ajax实现无刷新提交表单的方法,需要的朋友可以参考下
ASP.NET中防止刷新页面造成表单重复提交
jquery.form.js 无刷新异步提交表单js文件 /** * jQuery Form Plugin * version: 3.51.0-2014.06.20 * Requires jQuery v1.5 or later * Copyright (c) 2014 M. Alsup **/
前一段时间跟着师傅学到了另外几种无刷新提交表单的方法,主要是基于iframe框架实现的。现在整理出来分享给大家。 第一种: (html页面) HTML Code复制内容到剪贴板 <!DOCTYPE HTML> <html lang=en-...
开发完php提交表单后,当刷新页面的时候,php会自动提交,本文档提供了防止提交的方法
易语言网页表单自动提交例程源码,网页表单自动提交例程,获取网页对象,获取表单列表,取网页信息,取表单信息,刷新IE列表,枚举IE窗口,取句柄,取标题,取窗口数量,参数列表,提交,ObjectFromLresult,RegisterWindowMessage...
通常对于无刷新提交表单,我们都是运用ajax实现的。前段时间了解到另一种无刷新提交表单的方法。现在整理出来分享给大家。
使用ASP.NET MVC 开发 使用Ajax.BeginForm 提交表单 无刷新更新元素
通常对于无刷新提交表单,我们都是运用ajax实现的。前段时间跟着老大了解到另一种无刷新提交表单的方法,是利用iframe框架实现的。现在整理出来分享给大家。 第一种: html页面 <!DOCTYPE HTML> <...
基于jquery的实现不刷新页面的动态表单提交效果.zip