title: set ajax response in php variable
body: <p>I am trying to set json response in php variable.After success response my html data is printed in div.
  Any Idea How to upload This in a Php variable. it's any idea where I can store this in a session or cookies.</p>
  
  <pre><code>$('#pincode').on('change', function() {
      //const formData = $('#formid').serializeArray();
      var address = $("input[name=address]").val();
      var pincode= $("input[name=pincode]").val();
      var price = $("input[name=price]").val();
      var city = $("input[name=city]").val();
      var country =$('#country').val();
      var state = $('#state').val();
      //var state =$(this).val();
      //console.log(formData);
  
      $.ajaxSetup({
          headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
      });
  
      $.ajax({
          type:'POST',
          data:{address:address, pincode:pincode, price:price,country:country,state:state,city:city},
          url:'./ava',
          dataType: "text",
          success:function(data){
              $('#gettax').html(data);
              //alert(res);
          },
          error: function (err) {
              console.log(err);
              alert("Something Went Wrong, Please check again");
          }
      });
  });
  </code></pre>
  
  <p>Here is mY controller and I m returning a plan text value.and try to restore this in a php variable</p>
  
  <pre><code>public function avatax(Request $request){
      $input = $request-&gt;all();
      $address=$input['address'];
      $pincode=$input['pincode'];
      $country=$input['country'];
      $state=$input['state'];
      $city=$input['city'];
      $price=$input['price'];
      // print_r(json_decode(json_encode($input)));
      // die();
      //return response()-&gt;json(['success'=&gt;$input]);
  
      $client = new Avalara\AvaTaxClient('phpTestApp', '1.0', 'localhost', 'sandbox');
      $client-&gt;withSecurity('ABC', 'ABC');
      // If I am debugging, I can call 'Ping' to see if I am connected to the server
      $p = $client-&gt;ping();
      echo('&lt;h2&gt;Ping&lt;/h2&gt;');
      echo('&lt;pre&gt;' . json_encode($p, JSON_PRETTY_PRINT) . '&lt;/pre&gt;');
      if ($p-&gt;authenticated == true) {
          echo '&lt;p&gt;Authenticated!&lt;/p&gt;';
      }
  
      // Create a simple transaction for $100 using the fluent transaction builder
      $tb = new Avalara\TransactionBuilder($client, "ABC", Avalara\DocumentType::C_SALESINVOICE, 'ABC');
      $t = $tb-&gt;withAddress('SingleLocation',$address,null,null, $city,$state,$pincode, $country)
          -&gt;withLine($price, 1, null, "P0000000")
          -&gt;create();
  
      // echo('&lt;h2&gt;Transaction #1&lt;/h2&gt;');
      // echo('&lt;pre&gt;' . json_encode($t, JSON_PRETTY_PRINT) . '&lt;/pre&gt;');
      // echo '&lt;pre&gt;';print_r($t);
  
      $ta=$t-&gt;totalTax;
  
      // die();
      return response($ta)
          -&gt;header('Content-Type', 'text/plain');
  </code></pre>