title: $.ajax response generates error in content-Type:application/json for xml content in json
body: <p>This is very simple.I think i may be having an issue with incompatible response content type</p>
  
  <p>This is the code i am using to send a jQuery ajax request:</p>
  
  <pre><code> var settings = { dataType: 'json',
                  url: 'services/loadTemplate.ashx',
                  data: JSON.stringify({ 'Name': element.name }), // element.name },
                  processData: false,
                  //contentType: "application/json; charset=utf-8",
                  type: 'POST',
                  success: function (data) {
                  console.log('successData:'+data);
                      alert(data);
                  },
                  error: function (xhr, status, error) {
                      var err = eval("(" + xhr.responseText + ")");
                      alert(err.Message);
                  }
              }
              $.ajax(settings);
  </code></pre>
  
  <p>and this is the response i am trying to fetch in <code>success</code> callback.</p>
  
  <pre><code>{
    'name': 'sMan',
    'svg1': '&lt;svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="513" height="490"&gt;&lt;desc&gt;Created with Raphaël&lt;/desc&gt;&lt;defs&gt;&lt;/defs&gt;&lt;text x="50.5" y="50" text-anchor="middle" font="10px &amp;quot;Arial&amp;quot;" stroke="none" fill="#000000" font-size="0px" style="text-anchor: middle; font-style: normal; font-variant: normal; font-weight: normal; font-size: 0px; line-height: normal; font-family: Arial;"&gt;&lt;tspan&gt;Text&lt;/tspan&gt;&lt;/text&gt;&lt;image x="173.5" y="79.5" width="176" height="158" preserveAspectRatio="none" xlink:href="uploaded/75884f70-8872-49c1-8337-2cbbca626b2e.png" id="P28m" fill="#ff0000" stroke="#000000" stroke-width="1" fill-opacity="1" stroke-opacity="1" font-family="Calibri" style="stroke-width: 1px; fill-opacity: 1; stroke-opacity: 1; font-family: Calibri;"&gt;&lt;/image&gt;&lt;/svg&gt;',
    'svg2': ''
  }
  </code></pre>
  
  <p>But success is not fired.I am setting   <code>context.Response.ContentType = "application/json";</code> in the server side request handler and am simply writing the above string to response.Whats the correct way to do this?</p>
  
  <p><em><strong>EDIT</em></strong>:</p>
  
  <p>returning it this way:</p>
  
  <pre><code> return "{'name':'" + name + @"',
                  'svg1':'" + dt.Rows[0]["svg1"].ToString() + @"',
                  'svg2':'" + dt.Rows[0]["svg2"].ToString() + "'}";
  </code></pre>
  
  <p><strong>This worked:</strong></p>
  
  <pre><code> StringBuilder sb = new StringBuilder();
          StringWriter sw = new StringWriter(sb);
          using (JsonWriter jsonWriter = new JsonTextWriter(sw))
          {
              jsonWriter.Formatting = Formatting.Indented;
              //  jsonWriter.WriteStartArray();
              jsonWriter.WriteStartObject();
              jsonWriter.WritePropertyName("name");
              jsonWriter.WriteValue(name);
              jsonWriter.WritePropertyName("svg1");
              jsonWriter.WriteValue(dt.Rows[0]["svg1"].ToString());
              jsonWriter.WritePropertyName("svg2");
              jsonWriter.WriteValue(dt.Rows[0]["svg2"].ToString());
              jsonWriter.WriteEndObject();
  
             /* return "{'name':'" + name + @"',
                  'svg1':'" + dt.Rows[0]["svg1"].ToString() + @"',
                  'svg2':'" + dt.Rows[0]["svg2"].ToString() + "'}";*/
          }
  
          return sb.ToString();
  </code></pre>