dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
2629
share rss forum feed

dlsauers

join:2005-10-25
Wellston, OH

JQuery - remote page code load

In order to complete a task, it appears that my only solution is to use jQuery...

I am trying to load web site (php/html) into a jQuery variable

I looked at several examples..which state that doing the below is possible for a remote site... but I have no joy..

 
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<script type = "text/javascript">
$.get("http://www.somedomain.invalid", function(data){
alert("Data Loaded: " + data);
});
</script>
</body>
</html>
 

The above does NOT work if the site is REMOTE to my server

The above WILL WORK if the site is local ie:

$.get("http://www.mydomain.invalid", function(data){
alert("Data Loaded: " + data);
 
OR
 
$.get("index.php", function(data){
alert("Data Loaded: " + data);
 
 

php with remote access of data via fopen etc. is fine

Can jQuery not do this?? ? Several sites located via search, use the example above to do exactly what I am after to take the variable (data) and do what I need and then redisplay the web page in a new window.

I am after the source code of the page in the variable then to do my processing on parts and then redisplay it in a new window.


JAAulde
Web Developer
Premium,MVM
join:2001-05-09
Williamsport, MD
kudos:3

JavaScript, and therefore AJAX and jQuery, are limited to communication with the domain on which they're executed. This is a security precaution and cannot be overridden.

The only exception is JSONP, which requires cooperation on the part of the remote server.
--
The Yakabox | My Development Sandbox | LinkedIn Profile



cdru
Go Colts
Premium,MVM
join:2003-05-14
Fort Wayne, IN
kudos:7

said by JAAulde:

The only exception is JSONP, which requires cooperation on the part of the remote server.

Or Cross-origin resource sharing also allows it, but also requires some cooperation. The other alternatives is server side proxy or DNS alias.

There are limitations to all of the above, so there isn't one solution that fits all.

TuxRaiderPen

join:2009-09-19
reply to dlsauers

You might try

»simplehtmldom.sourceforge.net/


dlsauers

join:2005-10-25
Wellston, OH

said by JAAulde:
JavaScript, and therefore AJAX and jQuery, are limited to communication with the domain on which they're executed. This is a security precaution and cannot be overridden.
Well then then google and the various sites should quit listing this as a solution to this! Or prior versions allowed this and then changed it later... Now I know why I prefer PHP.

said by TuxRaiderPen:
You might try

»simplehtmldom.sourceforge.net/

THANKS!

Excellent! ! !

A PHP solution, no lame ECMAScript garbage! ! !

Problem solved, pulled in the code, erased the garbage and displayed the page! Perfect!

Thanks!