0

I am working on asp.net c# project and when I type url name like this: http://mydomain.com Jquery auto Complete doesn't work and gives error message but when I add www to it like this: www.mydomain.com it works...

Any Idea..?

Error Message :-

XMLHttpRequest cannot load http://www.mydomain.com/AutoComplete.asmx/GetAutoCompleteData. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.
Harshit Tailor
  • 3,261
  • 6
  • 27
  • 40

2 Answers2

3

www.example.com and example.com are different origins and you can't (FSVO can't) use JavaScript running on one to request data from the other.

Use a relative URI in your JavaScript, not an absolute one.

It would also be a good idea to run your site from one hostname, instead of two similar ones. Pick either www.example.com or example.com to be your canonical hostname and set up the other to redirect its traffic to it.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • button click also not working..give error Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0 – Harshit Tailor Feb 08 '13 at 09:46
  • @HarshitTailor — That's an entirely different problem, for which you haven't given enough information to solve. Ask a new question. – Quentin Feb 08 '13 at 09:49
2

It sounds like you're being caught by the Same Origin Policy.

My guess is you've hardcoded the link in the Autocomplete setup to www.mydomain.com, and when viewing the site view mydomain.com it counts as a cross-site request.

The solution is to make the AJAX request URL in the autocomplete setup relative.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • button click also not working..give error Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0 – Harshit Tailor Feb 08 '13 at 09:45
  • @HarshitTailor that's an issue with your server-side code. I'd start a new question about that. – Rory McCrossan Feb 08 '13 at 09:54