title: AJAX Request Error
body: <p>I get an error on submitting an ajax request.</p>
  
  <p>Here is the jQuery/ajax</p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
        $(function () {
            $('#BookButton').click(function (event) {
                var form = $('#Form1');
                $.ajax({
                    type: form.attr('method'),
                    url: form.attr('action'),
                    data: $("#BookRoom :input").serialize()
                }).done(function (data) {
                    $('#BookRoom').modal('hide');
                    if (data === ResponseType.Success) {
                        $('#SuccessMsg').text('Meeting Booked');
                        $('#SuccessMessage').modal('show');
                    }
                    else if (data === ResponseType.Reject) {
                        $('#SuccessMsg').text('There are conflicts');
                        $('#SuccessMessage').modal('show');
                    }
                    else if (data === ResponseType.Reject) {
                        // Notify user: It is your fault
                    }
                    else {
                        $('#SuccessMsg').text('Test');
                        $('#SuccessMessage').modal('show');
                    }
  
  
                    // Optionally alert the user of success here...
  
  
                    setTimeout(function () { $('#SuccessMessage').modal('hide'); }, 3000);
                }).fail(function () {
                    // Optionally alert the user of an error here...
                    alert("Error submitting AJAX request");
                });
                event.preventDefault(); // Prevent the form from submitting via the browser.
            });
        });
  </code></pre>
  
  <p></p>
  
  <p>Summary of C#</p>
  
  <pre><code>            public enum ReponseType : int
              {
              Success = 0,
              Reject = 1
  
                }
  
  
  
              if (ITMtgfapts.Items.Count &gt; 0) // If there is more than one item
              {
  
  
                  Response.AddHeader("Content-type", "application/json");
                  Response.ContentType = "application/json";
                  Response.Write(JsonConvert.SerializeObject(ReponseType.Reject));
                  Response.End();
              }
  
  
              else
              {
  
                  //Success
                  appointment.RequiredAttendees.Add(roomEmail);
  
  
  
                  appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
                  Response.AddHeader("Content-type", "application/json");
                  Response.ContentType = "application/json";
                  Response.Write(JsonConvert.SerializeObject(ReponseType.Success));
                  Response.End();
  
  
              }
  </code></pre>
  
  <p>Its worth noting that this is a WebForms application. When I submit the form I get the:</p>
  
  <pre><code>  alert("Error submitting AJAX request");
  </code></pre>
  
  <p>Error message. HOWEVER the C# still executes (i.e. it books a meeting room)</p>
  
  <p>Any ideas?</p>
  
  <p>Thank you</p>
  
  <p>EDIT:</p>
  
  <p>Fiddler Response</p>
  
  <pre><code>JSON:
  
  ResponseType=0
  </code></pre>
  
  <p>RAW:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: private
  Content-Type: application/json; charset=utf-8
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Tue, 14 Jan 2014 14:58:54 GMT
  Content-Length: 36
  
  {"ResponseType":0}{"ResponseType":1}
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>Got it working so this is now the response:</p>
  
  <pre><code>  HTTP/1.1 200 OK
    Cache-Control: private
    Content-Type: application/json; charset=utf-8
    Server: Microsoft-IIS/7.5
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Tue, 14 Jan 2014 15:15:28 GMT
    Content-Length: 18
  
    {"ResponseType":0}
  </code></pre>
  
  <p>I removed the code from the catch { } because when outputting the page as JSON it messed it up and caused it to catch.</p>
  
  <p>Now it is always returning </p>
  
  <pre><code>  else {
                    $('#SuccessMsg').text('Test');
                    $('#SuccessMessage').modal('show');
                }
  </code></pre>
  
  <p>Rather than success</p>
  
  <p>Ideas?</p>