This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Java Webserver - Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Java Webserver - Ajax" Watch "Java Webserver - Ajax" New topic

Java Webserver - Ajax

Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

I have created a simple webserver by java, when i request a file by url in browser for example it show page correctly but when i use Ajax it gave me nothing in fact xmlhttprequest.responseText is null. can anyone help me?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Is the request being sent by the browser? Is it being received by the server? If so, is everything OK so far? What is sent back? Is that OK? if so, what is received by the browser?
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

yes everything work fine, server sent back file with the http header 200 status code. i asked my question wrong, the right question is how to load page from different host by ajax. when i use by ajax it work but when i use it doesn't work.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63552

Ajax cannot do that. For security purposes, an Ajax request must be made to the same server that served the page.

You can write a server-side proxy that handles the request, or, if the server supports it, you can try JSONP if all you are interested in is GET requests.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Java Webserver - Ajax
jQuery in Action, 3rd edition