JQuery入口函数的几种书写
1.$(document).ready(function () { alert("Method one!"); });
2.jQuery(document).ready(function () { alert("Method two!"); });
3.$(function () { alert("Method three!"); });
4.jQuery(function () { alert("Method four!"); });
Ajax提交方式。
JS方式
- 创建Ajax引擎
- XMLHttpRequest对象发送ajax请求
open(method,url,async)
send([null]) - 处理响应数据
JQ方式
1.原始ajax请求
$.ajax({
url:’’,
type:’’,
dataType:’’,
data:’’,
headers:’’,
success:function(msg){
alert(“success”+msg) ; },
error: function(){
alert(“fail”); } });
2.get请求
$.get(url,function(msg){
alert(“Method_GET!”);
});
3.post请求
$.post(url,data,function(msg){
alert(“Method_POST!”);
});
4.上传文件
$(this).ajaxSubmit({
url:’’,
type:’’,
dataType:’’,
data:’’,
headers:’’,
success:function(msg){
alert(“upload success”+msg) ; },
error: function(){
alert(“upload fail”); }
});
return false; //防止多次提交