The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 5 of 5

Thread: Urgent help needed !!!

  1. #1

    Urgent 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
    !!!

  2. #2
    Use xmlHttpRequest...

    http://www.w3.org/TR/XMLHttpRequest/
    AS2 / AS3 / JS / JQUERY / (X)HTML / HTML5 / CSS / CSS3 / PHP

  3. #3
    Hi Thank you for the quick reply.Could you explain more about this.
    Thank you very much

  4. #4
    Untested code. Unsure how it will actually run since AJAX is asynchronous and would probably finish after the function returns....

    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>  
    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.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.

  5. #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>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012