up vote 1 down vote favorite

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

link|flag

1 Answer

up vote 1 down vote accepted

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

$.get('LoadComments.axd?storyID=' + storyID
link|flag
Hi Josh -- Yes, I do, and am able to verify that it is working by calling the URL directly from the browser. – adamisnt Sep 15 '09 at 15:38
1  
Try the updated answer, please. – Josh Stodola Sep 15 '09 at 15:40
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 Sep 15 '09 at 15:50
I do not believe the issue is with using an absolute URI, but with going over an abnormal port such as 56964. – Josh Stodola Sep 15 '09 at 17:17

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.