CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Ben Reichelt's Weblog


Cross Domain XmlHttpRequests (Ajax)



Comments

Brendan Tompkins said:

Ben,

This stuff is the future. A little remote scripting sprinkled on top, and this could really zing..

Just curious, though. Why the (Ajax) in the title?
# April 11, 2005 8:52 AM

breichelt said:

Brendan, I just wanted to make sure that people who have PubSub, Feedster, etc. feeds that are watching for the word "ajax" saw this post. And it is "ajax", we asynchronously get the rss feed, and then we use the DOM and dhtml to display the resulting xml in the browser.
# April 11, 2005 9:17 AM

Brendan Tompkins said:

I see... It looks like you were saying that "Cross-Domain XmlHttpRequests" = "Ajax" I'm still a bit confused myself, to tell you the truth... ;)
# April 11, 2005 10:05 AM

John Papa said:

Great timing, Ben. I just had a question today from a buddy of mine who is doing this but the XML coming in throws this exception when the XmlDocument.Load method is invoked:

'', hexadecimal value 0x12, is an invalid character. Line 1, position 6118.

Any idea on a recommended practice for stripping the character out or making it readable?
# April 11, 2005 10:06 AM

breichelt said:

Brendan - I understand the confusion, I didn't consider that when I made the title :) I simply put the word "Ajax" in there as sort of a meta keyword so that it would hit on google searches and whatnot. I generally don't care for the "ajax" term, but I realize that many people do.

John - I usually run into that problem when I'm making a request to a page that I expect to return xml, but then an asp.net exception gets thrown so the result is actually html content which makes the XmlDocument throw an error while its parsing.
# April 11, 2005 10:16 AM

John Papa said:

Ben, my friend is writing an RSS feed reader for SharePoint. The feed comes in most of the time as standard XML. But once in a while he gets the exception. I'm not sure what to tell him other than that he could read the entire string and strip out those characters (or write an event handler for it).

Oh well.
# April 11, 2005 10:23 AM

Eric Wise said:

Nice Ben. =)

Though you totally killed the post I was going to do on this in a week or two.

Great minds think alike...
# April 11, 2005 10:49 AM

Joshua Flanagan said:

HttpHandlers are also great for this type of thing.

Since they so thoughtfully included support for custom HttpHandlers in .NET (near the top of my list of favorite features), we no longer have to treat everything like a "page". I use the Page class when I want to render a UI. I use custom HttpHandlers when I just want to perform some service at an HTTP endpoint.

I'm sure the perf gain is minimal, but its nice from a design/code clarity perspective.
# April 12, 2005 11:39 AM

breichelt said:

Joshua, I just started experimenting with using a custom handler, it is pretty cool that you can interrupt the request like that. I'm using it to stream files to the user.

-ben
# April 12, 2005 11:46 AM

Ben Reichelt's Weblog said:

As kind of a followup to my post about how to redirect XmlHttpRequests outside your domain, which was...
# April 22, 2005 6:20 AM

Robin Curry said:

# April 22, 2005 8:07 AM

Robin Curry said:

# April 25, 2005 11:53 AM

Robin Curry said:

# April 25, 2005 11:54 AM

Jacek said:

Ben,

Great post!
But just so you know, post-SP2 IE <b>does</b> allow cross-domain use of Ajax provided that you add the site to your "Trusted Sites".
# August 31, 2005 6:08 AM

Adnan Siddiqi said:

In my last post,i mentioined about drawback of AJAX to use it across domain,you get Permission Denied...
# January 10, 2006 6:01 AM

Adnan Siddiqi said:

In my last post,i mentioined about drawback of AJAX to use it across domain,you get Permission Denied...
# January 15, 2006 4:26 AM

ray cheng said:

my only worry about doing this way is your server gets the content of the external domain instead of the client. if the client gets bad content, my server is still clean and safe. i won't want to put my server on risk.

ray
# February 27, 2006 8:55 PM
Check out Devlicio.us!

Our Sponsors

Free Tech Publications