1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<script>
        $(function(){
            $("#dianjiwo").click(function(){
               window.parent.postMessage(1,'*');
            });
            $("#idform").submit(function(e){
                alert($('#zlxg').val());
                if($('#zlxg').val()=="")
                {
                    alert('1');
                    return false;
                }
                else
                {
                    alert('2');
                    $.ajax({
                        url:"{:url('add')}",//這裡指向的就不再是頁面了,而是一個方法。
                        data:$("#idform").serialize(),
                        type:"POST",
                        dataType:"JSON",
                        success: function(msg)
                        {
                            if (msg.status==1)
                            {
                                alert(msg.txt);
                            }else
                            {
                                alert(msg.txt+msg.status);
                            }
 
                        },
                        error:function (msg)
                        {
                            alert(msg);
                        }
                    })
                }
            });
        })
        </script>
1
2
3
4
5
<form id="idform" method="post" action="url"></form>
 
第一種重新整理頁面:<input type="submit" >提交投票</input>
第二種無重新整理頁面:$("#idform").submit 改成 $(".submit").click
<form id="idform" method="post" action="url"> 改成 <form id="idform">
1
<br>

本文轉自 gutaotao1989 51CTO部落格,原文連結:http://blog.51cto.com/taoyouth/1933036