Answers.Body: <p>Any properties of the object you pass into <code>Craft.postActionRequest()</code>’s second argument will be available to Craft as POST parameters, so you can get to them with <a href="http://buildwithcraft.com/docs/apis/httprequestservice#getPost" rel="nofollow"><code>HttpRequestService::getPost()</code></a>:</p>
  
  <pre><code>$sData = craft()-&gt;request-&gt;getPost('Data');
  
  foreach ($sData as $temp)
  {
      $wine = $temp['wine'];
      // ...
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-24T07:51:28.393Z
Answers.Text: I think you're close... I think their data structure is actually an **array** of `temp` objects (containing "wine", etc). So I think they'll need to loop through `$data`, and pull the value of `wine` out of each object in the array.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-24T08:28:02.123Z
Answers.Text: I have added the full code above maybe you can get a better idea why I dont think i can do $data = craft()->request->getPost('Data'); as i have many of these 'Data' varaibles inside another array
Answers.UserDisplayName: user3309362
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-24T08:57:54.293Z
Answers.Text: @user3309362 Thanks, just updated my answer.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-24T07:22:52.440Z
Answers.LastActivityDate: 2014-06-24T08:57:34.143Z
Answers.LastEditDate: 2014-06-24T08:57:34.143Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have a JavaScript file which sends an array of data to a controller: </p>
  
  <pre><code>Craft.postActionRequest('wineNotes/wineSpreadSheet/saveWines', data, ...)
  </code></pre>
  
  <p>The structure of the data variable is as follows:</p>
  
  <pre><code>var data = {
      Data: sData
  }
  </code></pre>
  
  <p>... where <code>sData</code> is an array of temp variables <code>sData(temp1,temp2,...)</code> and the structure of each temp object is like this:</p>
  
  <pre><code>temp = {
      "wine":        ht.getDataAtCell(i,0),
      "country":     ht.getDataAtCell(i,1),
      "region":      ht.getDataAtCell(i,2),
      "note":        ht.getDataAtCell(i,3),
      "tastingdate": ht.getDataAtCell(i,4),
      "rating":      ht.getDataAtCell(i,5),
      "maturity":    ht.getDataAtCell(i,6),
      "conclusion":  ht.getDataAtCell(i,7)
  };
  </code></pre>
  
  <p>How can I access the parameter <code>temp.wine</code> for each <code>temp</code> in the <code>sData</code> array within the following method of my controller?</p>
  
  <pre><code>public function actionSaveWines()
  {
      // ???
  }
  </code></pre>
  
  <p>I know the data structure is kinda wierd its actually an array of arrays. Read the below code and you might understand.</p>
  
  <pre><code>for(i=0;i&lt;NumRows;i++)
          {
              temp = {
                  "wine":ht.getDataAtCell(i,0),
                  "country":ht.getDataAtCell(i,1),
                  "region":ht.getDataAtCell(i,2),
                  "tastingdate":ht.getDataAtCell(i,3),
                  "rating":ht.getDataAtCell(i,4),
                  "maturity":ht.getDataAtCell(i,5),
                  "conclusion":ht.getDataAtCell(i,6),
              };
              sData.push(temp);
          }
  
          var data = {
              Data: sData,
          }
          Craft.postActionRequest('wineNotes/wineSpreadSheet/saveWines', data, function(response) {
  
  
          });
  </code></pre>
  
Tags: <plugin-development><controller><ajax>
Title: How do I access AJAX data within a controller method?
ThreadText: # How do I access AJAX data within a controller method?
  
  (Asked by: username_0 on 2014-06-24)
  
  I have a JavaScript file which sends an array of data to a controller:
  
  ```
  Craft.postActionRequest('wineNotes/wineSpreadSheet/saveWines', data, ...)
  
  ```
  
  The structure of the data variable is as follows:
  
  ```
  var data = {
      Data: sData
  }
  
  ```
  
  ... where `sData` is an array of temp variables `sData(temp1,temp2,...)` and the structure of each temp object is like this:
  
  ```
  temp = {
      "wine":        ht.getDataAtCell(i,0),
      "country":     ht.getDataAtCell(i,1),
      "region":      ht.getDataAtCell(i,2),
      "note":        ht.getDataAtCell(i,3),
      "tastingdate": ht.getDataAtCell(i,4),
      "rating":      ht.getDataAtCell(i,5),
      "maturity":    ht.getDataAtCell(i,6),
      "conclusion":  ht.getDataAtCell(i,7)
  };
  
  ```
  
  How can I access the parameter `temp.wine` for each `temp` in the `sData` array within the following method of my controller?
  
  ```
  public function actionSaveWines()
  {
      // ???
  }
  
  ```
  
  I know the data structure is kinda wierd its actually an array of arrays. Read the below code and you might understand.
  
  ```
  for(i=0;i<NumRows;i++)
          {
              temp = {
                  "wine":ht.getDataAtCell(i,0),
                  "country":ht.getDataAtCell(i,1),
                  "region":ht.getDataAtCell(i,2),
                  "tastingdate":ht.getDataAtCell(i,3),
                  "rating":ht.getDataAtCell(i,4),
                  "maturity":ht.getDataAtCell(i,5),
                  "conclusion":ht.getDataAtCell(i,6),
              };
              sData.push(temp);
          }
  
          var data = {
              Data: sData,
          }
          Craft.postActionRequest('wineNotes/wineSpreadSheet/saveWines', data, function(response) {
  
          });
  
  ```
  
  **Tags:** plugin-development, controller, ajax
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-24. Score: 4
  
  Any properties of the object you pass into `Craft.postActionRequest()`’s second argument will be available to Craft as POST parameters, so you can get to them with [`HttpRequestService::getPost()`](http://buildwithcraft.com/docs/apis/httprequestservice#getPost):
  
  ```
  $sData = craft()->request->getPost('Data');
  
  foreach ($sData as $temp)
  {
      $wine = $temp['wine'];
      // ...
  }
  
  ```
  
  > **Comments:**
  > **username_2**: I think you're close... I think their data structure is actually an **array** of `temp` objects (containing "wine", etc). So I think they'll need to loop through `$data`, and pull the value of `wine` out of each object in the array.  
  > **username_0**: I have added the full code above maybe you can get a better idea why I dont think i can do $data = craft()->request->getPost('Data'); as i have many of these 'Data' varaibles inside another array  
  > **username_1**: @username_0 Thanks, just updated my answer.  
  
  ---
  
  