推荐阅读
相关文章
网站建设您当前位置: 主页 > 网络学院 > 网站建设

网站建设中的表单的提交

发布日期:2020-08-13 来源:优橙 浏览量:
摘要: 1:提交时提交: [/h 提交用于防止表单在提交前提交。如果错误,提交;如果是真的,不要提交! [/h 检查()是提交前的验证功能。如果不符合要求,返回false将阻止表单提交。以下是示例

1:提交时提交:



[/h
提交用于防止表单在提交前提交。如果错误,提交;如果是真的,不要提交!



[/h
检查()是提交前的验证功能。如果不符合要求,返回false将阻止表单提交。以下是示例文本:



复制代码


公式=' 4。PHP ' method=' post ' on submit=' returncheck()' enctype=' multipart/form-data '//enctype设置文件上传格式(该格式是上传文件所必需的)


输入id=' name ' type=' text ' placeholder='请输入名称'


input id=' paw ' type=' text ' placeholder='请输入密码'


input type=' file '


input type=' submit ' value=' submit '


/表格


复制代码


复制代码


脚本


check(){


var name=document . GetElementbyID(' name ');


var paw=document . GetElementBYID(' paw ');


if(name==''paw==''){


返回false


}否则{


返回真;


}


}


/脚本


复制代码






2:使用ajax的异步提交:



1:创建一个XMLHttpRequest核心对象(老师要求它要用心写)



复制代码


函数getXhr(){


var xhr=null


if(窗口。XMlhttprequest){


xhr=新的XMlhttprequest;IE8以外的其他浏览器{


}否则{



}


formaction=' 3。PHP ' method=' post ' id=' my form ' name=' my form '


}


复制代码


ii:建立连接并提交(帖子)



复制代码


车身


username:input type=' text ' id=' user ' name=' user ' br


password:input type=' text ' id=' paw ' br


input type=' button ' value=' submit ' id=' BTN '


/form


varbtn=document . getelement byid(' BTN ');


/车身


脚本


BTN . onclick=function(){


var Xhr=GetXhr();


xhr.open('post ',' 3 . PHP ');//与server


xhr . setrequest header(' content-type ',' application/x-www-form-URL encoded ')建立连接;//设置post的请求头


varuser=document . getelement by id(' user ')。价值;//获取名称值


varpaw=document . getelementbyid(' paw ')。价值;//获取paw值


xhr . send(' user='+user+' PAW='+PAW);//客户端向服务器


xhr . onreadystatechange=function(){//客户端接受服务器的响应



//以确保服务器响应的数据完全发送


if(xhr.readyState==4){


//以确保请求成功。状态代码200为成功


if(xhr.status==200){


//接受服务器端数据


var data=xhr.responseText


//test


console.log(数据);


}


}


}


}


/脚本


复制代码


ii:建立连接并提交(get)



复制代码


脚本


BTN . onclick=function(){


var Xhr=GetXhr();


BTN . onclick=function(){


var user=document . GetElementbyID(“用户”)。价值;//获取名称值


xhr . send(' user='+user+' PAW='+PAW);//客户端向服务器


varpaw=document . getelementbyid(' paw ')。价值;//获取paw值


xhr.send(空);//客户端向服务器发送请求



xhr . onreadystatechange=function(){//客户端接受服务器端响应


//以确保服务器响应的数据完全发送


if(xhr.readyState==4){


//以确保请求成功。状态代码200为成功


if(xhr.status==200){


//接受服务器端数据


var data=xhr.responseText


//test


console.log(数据);


}


}


}


}


}


复制代码


注意:发送不能从发布或获取中省略。get类型的发送是send(null ),无法向服务器发送请求数据









3。jQuery中的ajax提交:



 比较常用的



$get(url、数据、回调、类型)


//网址:提交地址数据:提交数据回调:回调函数类型:指定服务器端返回的数据格式。默认为超文本标记语言格式。其他格式包括xml和json。


//帖子和它一样,只是换成了帖子。


不常用



复制代码


$ajax({


Url:'4.php ',//设置请求地址


type:'post ',//设置请求方法


async:'true ',//设置异步请求


data: { name: ' David ',age:' 20'},//发送请求的数据 唯一键:value


success :函数(数据,文本状态){//回调函数


console.log(数据),成功后;


},


error:函数(xmlhttprequest,textstatus,errorstown){//失败后回调函数


console . log(text status);


},


})


复制代码



福州优橙互联网(Fuzhou Youcheng Internet),一家专注于福州网站建设的网站制作公司,为客户提供小程序制作,促进福州网络的全网推广和精准拓客。欢迎访问http://www.g303.com


全国统一客服热线

13809509600

周一至周五 9:00-22:30

法定节假日 9:00-23:00

微信公众号