This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Java Webserver - Ajax" Watch "Java Webserver - Ajax" New topic
Author

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 http://127.0.0.1:9328/index.html it show page correctly but when i use Ajax it gave me nothing in fact xmlhttprequest.responseText is null. can anyone help me?


http://www.myviwo.com
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41178
    
  45
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?


Ping & DNS - my free Android networking tools app
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 http://127.0.0.1:9328/index.html by ajax it work but when i use http://example.com/index.html it doesn't work.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: Java Webserver - Ajax
 
Similar Threads
access denied (SocketPermission 127.0.0.1:1099 connect,resolve)
importance of container in webserver
Java Webserver
Welcome Ryan Asleson and Nathaniel Schutta
Calling js(Ajax function) from html