1

I need to read a page content on my sub-domain using ajax get. I thought of creating some script on my sub-domain and calling that script on my domain. however I don't know how to do it.

Is it possible to do such a thing? how?

EDIT:

I created a page in my domain that uses DownloadString and downloads that page and write down the result. any better ideas?

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171

2 Answers2

1

If you wish to support cross-domain AJAX requests, you will need to create a cross origin resource sharing handler (CORS). I don't have an example specific to asp.net, but if you are using MVC this is fairly simply to achieve (and would be fundamentally the same for WebForms).

A Web API example may be found here to get you started: CorsHandler.cs

Also, if you need to support IE 7, 8 or 9 you would want to look in to a jQuery extension lib such as jQuery-ajaxTransport-XDomainRequest

EDIT

If you would like to look at a full example (again Web API unfortunately), here is a MSDN article with a full code example Implementing CORS support in ASP.NET Web APIs

Chris Baxter
  • 16,083
  • 9
  • 51
  • 72
0

You can also sometimes manipulate document.domain in JS. So if you're serving pages from www.site.com, and your Ajax services are hosted at app.site.com, set your document.domain to site.com.

joelt
  • 2,672
  • 2
  • 24
  • 32