Ajax response into javascript variables

In fact, I am working on a small PHP script and I use this code to make an ajax query

 var CODE = $('.code').val();
         var CASE = $('.code').attr('case');
  $.ajax({
            type:'POST',
            url:'ajax.php',
            data:'code='+CODE+'&case='+CASE,
            success:function(html){

            }
        });

the response is like that

<span class="name">Yassine</span>
<span class="email">[email protected]</span>

I want to store those results as javascript variables like this:

Var name = Yassine
Var email = [email protected]

Answers 1

  • You can use jQuery(), .eq(), .text()

    var response = $(html);
    var name = response.eq(0).text();
    var email = response.eq(1).text();
    

Related Articles