1

Possible Duplicate:
request content on another domain/server

am trying to make an ajax request to a php code using xmlHTTPrequest, my application works on tomcat server, and am trying to make a request to PHP code in WAMP server (different server with request URL localhost), my PHP code simply receives a parameter,makes a query in a PostgreSQL database,and returns the result in XML format...my main problem is how to send the ajax request to that PHP code from my application that run on Tomcat with URL localhost:8080... any help will be appreciated, thanks

Community
  • 1
  • 1
John silver
  • 105
  • 1
  • 6
  • 14
  • Please don't make duplicate questions: http://stackoverflow.com/questions/1933065/ajax-request-to-different-host http://stackoverflow.com/questions/4011156/how-to-request-different-domain-with-ajax-in-jquery http://stackoverflow.com/questions/8322202/request-content-on-another-domain-server http://stackoverflow.com/questions/7033976/cross-domain-javascript-ajax-request-status-200-ok-but-no-response – rkosegi Mar 10 '12 at 10:41
  • http://cmsnsoftware.blogspot.com/2012/02/how-to-use-cross-domain-ajax-request.html, http://stackoverflow.com/questions/8698682/ajax-call-working-fine-in-ie8-and-doesnt-work-in-firefox-and-chrome-browsers/8698786#8698786 – Chamika Sandamal Mar 10 '12 at 10:44

3 Answers3

1

You should access the PHP script from within your application running on the tomcat server. Not from the client side.

redDevil
  • 1,909
  • 17
  • 25
1

check the following link.

adding header header('Access-Control-Allow-Origin: *'); to the PHP code might solve the problem

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
user1109842
  • 23
  • 1
  • 8
0

you can't make an ajax request to a different domain. that's not allowed for security reasons. if both of your servers run on the same domain though there's no problem using ajax to request information.
using an javascript API like jQuery will make this a lot easier. here's how to perform ajax requests with jQuery

clem
  • 3,345
  • 1
  • 22
  • 33