Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Remote URLs with xmlHTTP
Old 11-03-2008, 05:59 PM Remote URLs with xmlHTTP
Novice Talker

Posts: 11
Name: Alex
Trades: 0
Take a look at the code below, specifically line: var url="http://www.example.com/code.php"

Code:
function exampleFunction(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="http://www.example.com/code.php"
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
For some reason, my html page struggles to pull this link. However, if I change:
Code:
 var url="http://www.example.com/code.php"
to:
Code:
 var url="code.php"
and drop the file in the same directory as my html file, I have no trouble executing the code.

Am I doing something wrong? Thanks!
pico204 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-03-2008, 06:28 PM Re: Remote URLs with xmlHTTP
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
JavaScript has a same origin policy, that does not allow it to read anything pulled from a path beginning with http://. It was designed that way to deter cross-site-scripting attacks against remote websites.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-03-2008, 08:59 PM Re: Remote URLs with xmlHTTP
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
To be more exact you cannot fetch from 1 domain, anything from another domain without using an server side proxy. The http:// has nothing to do with the mechanism.
If you stay on your site, you will be able to do absolutes (with http://) requests as well as relatives.
This to prevent malicious usage of ajax like web sites.

If you want to implement this "feature", you need to implement what is called an "ajax proxy": http://www.google.com/search?hl=en&l...=Google+Search
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Remote URLs with xmlHTTP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19130 seconds with 12 queries