title: PHP Curl - Get data generated with AJAX
body: <p>I want to get data generated by an AJAX request. In this page <a href="http://www.fipe.org.br/web/index.asp?p=51&amp;aspx=/web/indices/veiculos/default.aspx" rel="nofollow">http://www.fipe.org.br/web/index.asp?p=51&amp;aspx=/web/indices/veiculos/default.aspx</a> there are some html selects. When the user click on the first one (Marca), the second one is filled. I want to get this data.</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  $curl = curl_init();
  $postData = array('ddlAnoValor' =&gt;  0,
                                      'ddlMarca' =&gt; 1,
                                      'ddlModelo' =&gt; 0,
                                      'ddlTabelaReferencia' =&gt; 123,
                                      'txtCodFipe' =&gt; '');
  $result = null;
  $httpResponse = null;
  
  curl_setopt($curl, CURLOPT_URL, 'http://www.fipe.org.br/web/indices/veiculos/default.aspx?p=51');
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_REFERER, 'http://www.fipe.org.br/web/indices/veiculos/introducao.aspx');
  curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookies.txt');
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
  
  $result = curl_exec($curl);
  
  $httpResponse = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if($httpResponse == '404') {
      throw new exception('This page doesn\'t exists.');
  }
  
  echo $result;
  
  curl_close($curl);
  ?&gt;
  </code></pre>
  
  <p>Page request header</p>
  
  <pre><code>Host: www.fipe.org.br
  
  User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.13) Gecko/20100916 Iceweasel/3.5.13 (like Firefox/3.5.13)
  
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  
  Accept-Language: en-us,en;q=0.5
  
  Accept-Encoding: gzip,deflate
  
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  
  Keep-Alive: 300
  
  Connection: keep-alive
  
  X-MicrosoftAjax: Delta=true
  
  Cache-Control: no-cache, no-cache
  
  Content-Type: application/x-www-form-urlencoded; charset=utf-8
  
  Referer: http://www.fipe.org.br/web/indices/veiculos/default.aspx?p=51
  
  Content-Length: 9415
  
  Cookie: __utma=106123796.1351303072.1287075522.1287075522.1287075522.1; __utmb=106123796; __utmc=106123796; __utmz=106123796.1287075522.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); ASPSESSIONIDAADQDQRD=EKBEJHEDKCIOAAHNFFMLGMKO
  
  Pragma: no-cache
  </code></pre>
  
  <p>But I always get the form as result. I've tried to set cookie but cookies.txt file is always empty. I don't know if this cookie is required. cookies.txt has 777 permission. What am I doing wrong? Thank you.</p>