jquery使用ajax提交form表单

 

        $.ajax({
            type: jqform.attr('method'), // 提交方式 get/post
            url: jqform.attr('action'), // 需要提交的 url
            data:jqform.serialize(),
            success: function(json) { //
                var json = eval('(' + json + ')');
                if(json.state) {
                    alert('修改成功!');
                    ct.assoc.close();
                    return true;
                }else{
                    ct.error(json.error);
                }
            }
        });
        return false; // 阻止表单自动提交事件

 

 1 ;(function($){
 2     //跨域传输
 3     var jqform = $('form');
 4 
 5     $(':button').click(function(){
 6         var url = jqform.attr('action')+'&jsoncallback=?';
 7         var data = jqform.serialize();
 8         console.log(url);
 9         $.getJSON(
10             url,
11             data,
12             function(res){
13                 console.log(res);
14             }
15         );
16         return false; // 阻止表单自动提交事件    
17     });
18 
19 })(jQuery);
20 
21 <?php
22 $res =$this->json->encode(array('total'=>$total,'data'=>$data));
23 echo $_GET['jsoncallback'] ."(".$res.");";
24 ?>

 

posted on 2017-07-03 14:55  天涯尘星  阅读(537)  评论(0编辑  收藏  举报

导航