Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Webserver - Ajax

 
Javad Rashidi
Ranch Hand
Posts: 34
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic