wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax doubt - url in open method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax doubt - url in open method" Watch "Ajax doubt - url in open method" New topic
Author

Ajax doubt - url in open method

omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
Hello friends,

I have a doubt in ajax. Can i give a complete url in the open method of the XMLHttpRequest object ? like for example: -



I tried to debug this using the firebug plug-in in Firefox. I am using Firefox 3.0.5. While debugging, after the request is sent, the script pane of the debugger loads with a page related to google, but the screen does not show anything related to google.

In IE, unfortunately there is no debugger to go line by line, but the result is the same as Firefox - nothing happens !!!

Can some one please help me with the problem?


Thanks and Regards
Omkar Patkar (SCJP 1.4)[url]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/url]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Scroll to the Security Section in this article: http://developer.apple.com/internet/webcontent/xmlhttpreq.html

That will tel you why it does not work.

Eric
omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
Thank you so much Eric. Now i understand that, cross domain access is not possible. Which also means that, the responseText can never contain, a response given by a resource from some other domain.

But i have another doubt related to this,

What if the there is a need to access third party application to show updates about something at regular intervals on a part of page without refresh...like for example ... news ? or weather? or cricket/football match score? How can this be achieved in such a scenario?

Another doubt, let's say i have hosted two web applications on abc.com as app1 and app2.

If i want to access app1 i will hit the url as : -
http://abc.com/app1/home.htm

if i want to access app2 i will hit the url as : -
http://abc.com/app2/welcome.htm

in such an environment, can i access app2 from app1 using Ajax, as their domains are same that is "localhost" ?

For example, in Ajax script of home.htm of app1 if i write,

xmlHttpObj.open("GET", "http://abc.com/app2/welcome.htm", true);

is that allowed in AJAX? Million thanks in advance
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can access any files on the same domain, but sub domains are seen as different domains

so if the address bar reads http://example.com/blue/house.html

Good:
  • http://example.com/hey
  • http://example.com/foo
  • http://example.com/bar/brain/candy


  • bad:
  • http://sub1.example.com/hey
  • http://example123.com/
  • http://an.example.com/blue/house.html


  • If you want to access a 3rd party site you either need to use a proxy on your server or you can use a JSON request if they offer a JSON Web Service. Here is an example of mine that calls a yahoo webservice with JavaScript http://www.pascarello.com/examples/JsonYahooExample.html

    Eric
    omkar patkar
    Ranch Hand

    Joined: Aug 25, 2005
    Posts: 231
    Thanks for all the info Eric. I am learning AJAX. I don't know how JSON works, so i did not understand the JSON example. But i got your point. Thanks ! Don't mind if i ask you more doubts, when i start learning JSON ... he he he!

    ... thanks and Merry Xmas and a Happy new Year!!! to all java ranchers!!!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Ajax doubt - url in open method
     
    Similar Threads
    Doubt in this()
    == doubt
    Doubt
    iterate doubt
    Doubt in Specs