开发者

jquery ajax success function

开发者 https://www.devze.com 2023-03-18 05:40 出处:网络
<script type=\"text/javascript\"> var $stars = $(\"#formStars{{ item.url }}\") $stars.click(function(){
<script type="text/javascript">
                    var $stars = $("#formStars{{ item.url }}")
                    $stars.click(function(){
                        var value = $("input:radio[name={{ item.url }}]:checked", this).val(),
                            item = 开发者_如何学编程"{{ item.url }}",
                            user = "{{ user }}";

                        $.ajax({
                            type: "GET",
                            url: "/addvote/",
                            data: "item="+item+"&user="+user+"&value="+value,
                            success: function(){
                                $("input:radio[name="+item+"]").attr("disabled", "disabled");
                            }
                        });
                    });             
                </script>

Don't work the success function, input not disabled, but if i reload the page it becoms disabled...


Try wrapping your function in the a document.ready

$(document).ready(                    
                    var $stars = $("#formStars{{ item.url }}")
                    $stars.click(function(){
                        var value = $("input:radio[name={{ item.url }}]:checked", this).val(),
                            item = "{{ item.url }}",
                            user = "{{ user }}";

                        $.ajax({
                            type: "GET",
                            url: "/addvote/",
                            data: "item="+item+"&user="+user+"&value="+value,
                            success: function(){
                                $("input:radio[name="+item+"]").attr("disabled", "disabled");
                            }
                        });
                    }); 
);

This makes sure the dom elements are loaded before attempting to manipulate them.

0

精彩评论

暂无评论...
验证码 换一张
取 消