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

时间:2023-01-19 23:26:14
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 个解决方案

#1


0  

Working Code...Just use async: false

工作代码......只需使用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");

#1


0  

Working Code...Just use async: false

工作代码......只需使用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");