简体   繁体   中英

Return Value From AJAX Outside AJAX Call

I want the html value of AJAX in outside of AJAX Call or in the $('#username').blur(function() function.. Is this possible?

   <script>
        $(document).ready(function() {
            $('#username').blur(function() {
                var username = $(this).val();
                availibilityCheck(username);
            })
    
            function availibilityCheck(username) {
                var result = "";
                $.ajax({
                    url: "action.php",
                    method: "POST",
                    data: {
                        action: "availibilityCheck",
                        data: username
                    },
                    dataType: "text",
                    success: function(html) {
                        $('#usernameresponse').html(html);
                    }
                })
            }
        });
    </script>
<script>
        $(document).ready(function() {
            $('#username').blur(function() {
                var username = $(this).val();
                availibilityCheck(username);

                var return_first;
                function callback(response) {
                  return_first = response;
                  //use return_first variable here
                }
                
                
                
            })
    
            function availibilityCheck(username) {
                var result = "";
                $.ajax({
                    url: "action.php",
                    method: "POST",
                    data: {
                        action: "availibilityCheck",
                        data: username
                    },
                    dataType: "text",
                    success: function(html) {
                     callback(html);
                        $('#usernameresponse').html(html);
                    }
                })
            }
        });
    </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM