title: Symfony Access ajax JSON response in separate controller method
body: <p>I have a controller with a method/route <code>assistantsActionView()</code> that  builds two forms then renders a Twig template. Within that template I have a user action modal which at one point sends an ajax request to a separate function <code>handleAjax()</code> which returns a response, then displays info accordingly. </p>
  
  <p>However, I need to access one of the objects that is sent via the JSON Response in <code>assistantsActionView()</code>. How can I go about this?</p>
  
  <pre><code> public function handleUserSearchAjaxRequest(Request $request, $courseSpace)
      {
       // handle the ajax, return response
       $outputData = [
              'output' =&gt; $errorCount . ' other assistants will not be added',
              'notFoundOutput' =&gt; ' were not found in the directory:',
              'notFoundUsers' =&gt; $notFoundUsers,
              'existingOutput' =&gt; ' already have access to this course space:',
              'existingUsers' =&gt; $existingAssistants,
              'validUsers' =&gt; $validUsers, // ** This is the data I need to access in the dB**
              'valid' =&gt; $isValid,
              'maxAssistantsOutput' =&gt; $maxAssistantsOutput,
              'maxUsers' =&gt; $maxUsers,
              'extraUsersCount' =&gt; $extraUsersCount
          ];
          return new JsonResponse($outputData);
  
      }
  
  // The controller
  
   public function assistantEnrollmentAction(Request $request, ListSettings $listSettings, CourseSpace $courseSpace)
      {
          $form = $this-&gt;createForm(AddAssistantType::class);
          $form-&gt;handleRequest($request);
          $bulkAddForm = $this-&gt;createForm(UserBulkAddType::class);
          $bulkAddForm-&gt;handleRequest($request);
  
         // Handle forms and stuff
           if ($bulkAddForm-&gt;isSubmitted() &amp;&amp;  $bulkAddForm-&gt;isValid()) {
            // here I need to access the validUsers data sent in the JSON response
  
          }
      }
  </code></pre>