码迷,mamicode.com
首页 > Web开发 > 详细

jquery使用ajax提交form表单

时间:2017-07-03 16:16:57      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:自动   跨域   callback   pre   提交   type   att   表单   this   

 

        $.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 ?>

 

jquery使用ajax提交form表单

标签:自动   跨域   callback   pre   提交   type   att   表单   this   

原文地址:http://www.cnblogs.com/GNblog/p/7111163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!