Adam
Adam

Reputation: 612

Using jQuery with HttpHandlers

I am trying to return HTML from a HttpHandler via jQuery. I am using the following jQuery javascript to call the handler:

$.get('http://localhost:56964/LoadComments.axd?storyID=' + storyID ,function(data) {
alert(data);
});

The handler performs some processing and returns HTML. The problem I am having is that the above call results in a 404 with no response. If I call the same URL as above in the browser, the HTML is returned back to the browser, no problem.

I am setting the following Response headers in the handler:

 context.Response.ContentType = "text/html";
 context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
 context.Response.Cache.SetNoStore();
 context.Response.Cache.SetExpires(DateTime.MinValue);
 context.Response.StatusCode = 200;

 context.Response.Write(sb.ToString());

If it matters, part of the returned HTML contains a script block, wrapped in script tags. I am guessing it does not matter since it works fine when calling directly from the browser.

I cannot figure out what is going wrong. Please help :P

Thanks, Adam

Upvotes: 1

Views: 951

Answers (1)

Josh Stodola
Josh Stodola

Reputation: 82483

Have you tried just using a relative URL? As in:

$.get('LoadComments.axd?storyID=' + storyID

Upvotes: 1

Related Questions