title: json request return html in rails
body: <p>I'm currently trying to make a Ajax script to communicate with an Rails server on my localhost (for now). The problem is that I specify in my $.ajax request that I want the format in 'json' but rails returns a 'html' format:</p>
  
  <pre><code>$(document).ready(function(){
  
  $('form').on("submit",function(){
      $.ajax({
          contentType: 'application/json; charset=utf-8',
          url : "http://192.168.0.36:3000/?value=10",
          type : "GET",
          dataType : 'JSON',
          success: function(data){
              alert(JSONParsedata(data));
          },
          error: function(XMLHttpRequest, textStatus, errorThrown)
          {
              alert(textStatus +", " +errorThrown);
          }
      });
  
  
      return false;
  })
  </code></pre>
  
  <p>In the console log of the rails server, I can read:</p>
  
  <p>Processing by WelcomeControllerindex as HTML
  ...
  Completed 200 OK in 34ms...</p>
  
  <p>I actually receive a response from the server, but in a HTML format instead of JSON.</p>
  
  <p>I precise that my rails controller for welcomeController code contains the:</p>
  
  <pre><code> respond_to do |format|
    format.html
    format.json { render :json =&gt; @z }
  end
  </code></pre>
  
  <p>z is a variable I want to send back to the Ajax request and is defined before (i lighted the code to make it understandable)</p>
  
  <p>As a result, Jquery is trying to parse the result in a JSON format and then finish by a : 
  parsererror syntaxerror unexpected token '&lt;' 
  Which correspond to the first character  of the full page!</p>
  
  <p>I searched for hours and I don't know how to resolve this. </p>
  
  <p>Thank you very much for your help</p>