Getting ajax response value

want to get value from my ajax response

and compare it

am just trying it like this

var getthis = $('#results').text(res.msg);

but not working

and a complete code is

<script>
  $(document).ready(function () {
    $("#Submit").click(function(event) {
       Execute();
    });

    function Execute(){
      $.ajax({
        type: 'POST',
        url: 'somefile.php',
         success: function(res) {
    var getthis = $('#results').text(res.msg);
  },
     if (getthis == "sayhello") {
     // do something
     }else{
         // do something    
       
     }
      });
    };

  });
</script>

Could you give more information? What does “not working” mean?

am not getting var value for getthis

My bet is that you need to parse the variable ->

do this

console.log(res);

to see what i looks like.

I haven’t coded in jQuery in a long time and someone else will probably give you a better answer. However, this should help you debug it on your own…maybe?

i dont think so, coz i have solved it without parsing

5 Likes