Results 1 to 5 of 5
Thread: Urgent help needed !!!
-
October 27th, 2009, 10:55 AM #12Registered User
postsUrgent help needed !!!
Hi Guys,
Please help me with this.I have stuck on my project work
What i want is load souce code of a specific domain into a variable using javascript/ajax.
EG
Var get_S=getSouce("http://<domin name.com">);
alert(get_s);
After that source code should be displayed in an alert box
Please help me to solve this problem...
Thank you very much
!!!
-
October 27th, 2009, 11:34 AM #2
Use xmlHttpRequest...
http://www.w3.org/TR/XMLHttpRequest/AS2 / AS3 / JS / JQUERY / (X)HTML / HTML5 / CSS / CSS3 / PHP
-
October 27th, 2009, 12:24 PM #32Registered User
postsHi Thank you for the quick reply.Could you explain more about this.
Thank you very much
-
October 28th, 2009, 01:01 AM #4
Untested code. Unsure how it will actually run since AJAX is asynchronous and would probably finish after the function returns....
This is also untested but could be safer than the one above:HTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript"> </script> <script type="text/javascript"> //<![CDATA[ function getSource(url) { new Ajax.Request( url, { method: 'get', onSuccess: function(transport) { return transport.responseText; } } ); } new Event.observe( window, 'load', function() { alert(getSource('http://www.yahoo.com')); } ); //]]> </script> </head> <body> </body> </html>
HTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript"> </script> <script type="text/javascript"> //<![CDATA[ function getSource(url) { new Ajax.Updater( 'outputSourceHere', url, { method: 'get' } ); } new Event.observe( window, 'load', function() { getSource('http://www.yahoo.com'); } ); //]]> </script> </head> <body> <pre id="outputSourceHere"></pre> </body> </html>
Last edited by NeoDreamer; October 28th, 2009 at 01:06 AM.

-
October 28th, 2009, 10:42 PM #5
Same thing with jQuery only less lines of code and more functionally.
If your just starting out with Javascript I highly recommend jQuery as there are way more tutorials and is used more widely then prototype.
HTML Code:<!DOCTYPE html> <html> <head> <title>Test</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script> $(document).ready(function() { $('#url-source').submit(function() { $.get($('#url-to-get').val(), function(data) { $('#outputSourceHere').text(data); }); return false; }); }); </script> </head> <body> <form id="url-source" action="#" method="get" accept-charset="utf-8"> <label for="url-to-get">URL</label> <input type="text" name="url-to-get" value="http://yahoo.com" id="url-to-get" /> <input type="submit" value="Get Source" /> </form> <pre id="outputSourceHere"></pre> </body> </html>

Reply With Quote

Bookmarks