• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax doubt - url in open method

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 231
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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!!!
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic