Hey there! any question in your mind? Ask It Now!.

Popular Categories





I want to return the response from AJAX call?

+1 vote
137 views
asked in Programming by navneet (270 points)

i am trying like this:

function fun() {
    var result;

    $.ajax({
        url: '...',
        success: function(response) {
            result = response;
            // return response; // <- tried that one as well
        }
    });

    return result;
}

var result = fun();

2 Answers

0 votes
answered by jatin Expert (3,823 points)

you can use these Steps.

  1. Make the AJAX call synchronous (lets call it SJAX).
  2. Restructure your code to work properly with callbacks
0 votes
answered by amit_pammu Expert (5,030 points)
for the response ..firstly you have to call the particular action of urs url!!..

than you have to generate the response there!

than print the result on your action!.

and youe code must as follow

<script>

        $(document).ready(function() {
            $('#source').change(function() {
                var Filter = $(this).val();
                $.ajax({
                    type: "POST",
                    url: "complete url",
                    data: {Filter: Filter},
                    success: function(result) {
                        $("#target").html(result);
                    }
                });
            });
        });

    </script>

Related Questions

+4 votes
5 answers 3,626 views
+1 vote
1 answer 870 views
0 votes
1 answer 145 views
0 votes
2 answers 329 views
+1 vote
1 answer 1,022 views
+4 votes
1 answer 140 views
0 votes
1 answer 119 views

Not a Member yet?

Ask to Folks Login

My Account
350 Folks are online
0 members and 350 guest online
Your feedback is highly appreciated