I have a Web page within my application that needs to call a web service I have set up to return a list of objects. This call is set up like so
$(document).ready(function() {
var response = $.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: '/Ajax/service.asmx/GetObjects'
});
response.success(function(data) {
$('#bodyText').html(data);
});
response.complete(function() {
alert('ajax complete');
});
});
My service looks like this
namespace AjaxTest.Ajax
{
#region
using System.ComponentModel;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;
#endregion
/// <summary>
/// Summary for boat
/// </summary>
[WebService(Namespace = "http://quality/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Boat : WebService
{
#region Public Methods and Operators
/// <summary>
/// The Get Models method.
/// </summary>
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetModels()
{
var models = Com.somedll.GetModels();
var serializer = new JavaScriptSerializer();
var response = models.Count != 0
? serializer.Serialize(models)
: serializer.Serialize(new Error { Code = "500", Message = "Model Retrieval Failed" });
this.Context.Response.Clear();
this.Context.Response.ContentType = "application/json";
this.Context.Response.Flush();
this.Context.Response.Write(response);
}
#endregion
}
}
I am getting the following errors Server cannot append header after HTTP headers have been sent. and looking at Firebug the request seems to be being sent multiple times at least 4 for each request, can anyone help. Please let me know if you need any more information