如何在jquery中从成功块中访问成功数据

时间:2013-02-19 05:08:14

标签: javascript jquery ajax

jQuery.validator.addMethod("uniquerheading", function(value, element) {     
        var data = false;
        $action_name = 'checkunquieannoucementheading';

        var url = '<?php echo "$module_name/$controller_name/checkunquieannoucementheading"; ?>';
        $.ajax({
             url: url,
             type: 'get',
             data: {
                "txt_heading":value             
             },
             success: function(data) {              
                // Display list on the page by replacing the content on existing, get from the controller-action
                return data;
             }
        });


}, "Annoucement heading already used");

1 个答案:

答案 0 :(得分:0)

工作代码......只需使用async:false

jQuery.validator.addMethod("uniquerheading", function(value, element) { 

        $action_name = 'checkunquieannoucementheading';
        var response = false;
        var url = '<?php echo "$module_name/$controller_name/checkunquieannoucementheading"; ?>';
            $.ajax({
            url: url,
            type: 'get',
            data: {
                    "txt_heading":value             
            },
            success: function(data) {               
                // Display list on the page by replacing the content on existing, get from the controller-action
                response =  data;
            },
            async:   false
        })

        return response;

}, "Annoucement heading already used");