title: JSON and jQuery.ajax
body: <p>im trying to use the jQuery UI autocomplete to communitate with a webservice with responseformate JSON, but i am unable to do so.</p>
  
  <p>My webservice is not even executed, the path should be correct since the error message does not complain about this.</p>
  
  <p>What strikes me is the headers, response is soap but request is json, is it supposed to be like this?</p>
  
  <pre><code>Response Headersvisa källkod
  Content-Type application/soap+xml; charset=utf-8
  
  
  Request Headersvisa källkod
  Accept application/json, text/javascript, */*
  Content-Type application/json; charset=utf-8
  </code></pre>
  
  <p>The error message i get is as follows (sorry for the huge message, but it might be of importance):</p>
  
  <p>soap:ReceiverSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
     at System.Xml.XmlTextReaderImpl.Throw(Exception e)
     at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
     at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
     at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
     at System.Xml.XmlTextReaderImpl.Read()
     at System.Xml.XmlTextReader.Read()
     at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
     at System.Xml.XmlReader.MoveToContent()
     at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
     at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
     at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
     at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
     at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
     at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)
     --- End of inner exception stack trace ---</p>
  
  <p>This is my code:</p>
  
  <pre><code>$('selector').autocomplete({   
     source: function(request, response) {
                  $.ajax({
                      url: "../WebService/Member.asmx",
                      dataType: "json",
                      contentType: "application/json; charset=utf-8",
                      type: "POST",
                      data: JSON.stringify({prefixText: request.term}),
  
                      success: function(data) {
                          alert('success');
                      },
                      error: function(XMLHttpRequest, textStatus, errorThrown){
                          alert('error');
                      }
                  })
                  }, 
     minLength: 1,
     select: function(event, ui) {
  
     }
    });
  </code></pre>
  
  <p>And my webservice looks like this:</p>
  
  <pre><code>[WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  [ScriptService]
  public class Member : WebService
  {
  
      [WebMethod(EnableSession = true)]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
      public string[] GetMembers(string prefixText)
      {
         code code code
      }
  
  }
  </code></pre>
  
  <p>What am i doing wrong? Thanks in advance :)</p>