views:

184

answers:

1

Hello,

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

+1  A: 

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

$.get('LoadComments.axd?storyID=' + storyID
Josh Stodola
Hi Josh -- Yes, I do, and am able to verify that it is working by calling the URL directly from the browser.
adamisnt
Try the updated answer, please.
Josh Stodola
Well, WTF. That works. Is there some limitation with the jquery call that does not allow the use of absolute URLs? Glad to get this answered, it was driving me insane. Thanks :)
adamisnt
I do not believe the issue is with using an absolute URI, but with going over an abnormal port such as 56964.
Josh Stodola