ajax方法的用法

来源:互联网 发布:下载手机app软件 编辑:程序博客网 时间:2024/05/20 02:51
$.ajax({   type : "POST",   url : "test.do",   data : text,   async : false,   dataType : "json",   success : function(res) {     aler("test");       },   error : function(res) {       },   complete : function() {   }});
dataType : "json", 
服务器端返回的数据格式  json格式  也可以是text等类型
 async : false   默认是true       false  表示为同步 什么意思呢?  意思就是要等test.do 完成后才会执行
                                  aler("test");这个操作  如果为true 的话就是还没执行完test.do  就执行
                                  aler("test"); 但是这个地方就说报错 因为没有返回值 或者说test.do执行出错了依然会执行在test.do后面可以放通过以下方式存放数据:  
1:"${context_root}/bmbucbp1/bui570002.do?&cop_bus_typ="      + cop_bus_typ+"&old_jrn_no="+old_jrn_no+"&old_ord_no="+old_ord_no,
2: 在data 里面放json格式的数据 data:{"applyNumber":applyNumber},
        
3:text= "&cop_bus_typ="+cop_bus_typ
data:text

4:var params = $("#addform1").serialize(); // http request parameters. 
jQuery的serialize()方法通过序列化表单值
data:params

contentType  发往服务器的格式 默认是 "application/x-www-form-urlencoded"
dataType是 服务器端返回数据格式

http://cnn237111.blog.51cto.com/2359144/984466


0 0