【jQuery】Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
来源:互联网 发布:我的阿里云tv工程模式 编辑:程序博客网 时间:2024/04/29 23:30
$.get(url,[data],[callback])
说明:url为请求地址,data为请求数据的列表(是可选的,也可以将要传的参数写在url里面),callback为请求成功后的回调函数,该函数接受两个参数,第一个为服务器返回的数据,第二个参数为服务器的状态,是可选参数。而其中,服务器返回数据的格式其实是字符串形势,并不是我们想要的json数据格式,在此引用只是为了对比说明。
$.get("data.php",$("#firstName.val()"),function(data){ $("#getResponse").html(data); }//返回的data是字符串类型 );
$.post(url,[data],[callback],[type])
说明:这个函数跟这个函数跟.get()参数差不多,多了一个type参数,type为返回的数据类型,可以是html,xml,json等类型,如果我们设置这个参数为:json,那么返回的格式则是json格式的,如果没有设置,就和.get()返回的格式一样,都是字符串的。
$.post("emp.do?p=getAllEmp",{id:deptId,x:Math.random()},function(data){ var arry = eval("("+data+")");//去引号,将json字符串去引号编程json类型数组,也可以在$.post函数后面加一个参数"json",指定接收的数据为json类型的 for(var i=0;i<arry.length;i++){ var op = new Option(arry[i].empName,arry[i].empId); document.getElementById("emp").options.add(op); }});
也可以写成下面这样,返回的就是json类型数组了,就不要难过去引号了,可以直接遍历:
$.post("emp.do?p=getAllEmp",{id:deptId,x:Math.random()},function(arry){ for(var i=0;i<arry.length;i++){ var op = new Option(arry[i].empName,arry[i].empId); document.getElementById("emp").options.add(op);5 }},"json");
$.ajax(opiton)
说明:$.ajax()这个函数功能强大,可以对ajax进行许多精确的控制,需要详细说明的请参照相关资料
$.ajax({ url: "ajax/ajax_selectPicType.jsp", data:{Full:"fu"}, type: "POST", dataType:'json', success:CallBack, error:function(er){ BackErr(er);}});
$.getJSON(url,[data],[callback])
说明:$.getJSON(url,[data],[callback])函数没有type参数,返回的是json类型的,不需要转换。
$.getJSON("dep.do?p=getAllDep",{x:Math.random()},function(arry){ for(var i=0;i<arry.length;i++){ var op = new Option(arry[i].deptName,arry[i].deptId); document.getElementById("dep").options.add(op); }});
0 0
- 【jQuery】Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- jQuery $.ajax() $.get() $.post() $.getJSON()
- jQuery中各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读jQuery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- 详细解读Jquery各Ajax函数,$.get(),$.post(),$.ajax(),$.getJSON()
- linux系统初次使用cmake编译boost项目
- Lock与synchronized是不一样的
- mysql备份还原(视图、存储过程)
- OC中的内存管理
- virtualbox下ubuntu共享文件夹自动挂载
- 【jQuery】Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
- maven项目中自动下载jar包的pom.xml配置
- android:layout_width与android:width的区别
- LeetCode 102 : Binary Tree Level Order Traversal(Java)
- NStimer(计时器)实现按钮的发送验证码的一个小demo
- 新手学EasyUI(八)----SubGrid三级嵌套
- 自适应增益AGC算法
- 王学岗的属性动画上(二)——objectAnimator的非主流用法
- 求教,CSS3绚丽照片墙JS代码及其中遇到的问题