简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM