Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get text content from another website by javascript in asp.ne

Status
Not open for further replies.

ravib21

Programmer
Mar 23, 2011
1
US
hello...
i'm creating a web application in asp.net in which i would like to give user a one JavaScript code, through which the user can get content from my website to his/her own website.

i've used one generic handler to process user request in my website.

so, now How can i do this, i've tried using jQuery..
jQuery can only process requests from current server, not from other server (if i'm not wrong)

code on

<script type="text/javascript" src="jquery.x.x.js">
</script>
<script type="text/javascript">
$('#result').load('</script>
<body>
<div id="result">

</div>

</body>


Above code isn't working.. :(

is there any other way to send content from my website to other website??

any help would b greatly appreciated.
-thanx
 
Hi

You can do it with AJAX too. See my post at 4 Feb 10 4:33 in thread215-1589249.

The usual solution is to serve the content as JSON and let the remote site handle it with JavaScript :
JavaScript:
[teal]<[/teal]script type[teal]=[/teal][green][i]"text/javascript"[/i][/green] src[teal]=[/teal][green][i]"[URL unfurl="true"]http://myWebSite.com/getData.ashx"[/URL][/i][/green][teal]></[/teal]script[teal]>[/teal]
[teal]<[/teal]script type[teal]=[/teal][green][i]"text/javascript"[/i][/green][teal]>[/teal]
$[teal]([/teal][green][i]'#result'[/i][/green][teal]).[/teal]innerHTML[teal]=[/teal]ravib21[teal].[/teal]text
[teal]</[/teal]script[teal]>[/teal]
[teal]<[/teal]body[teal]>[/teal]
[teal]<[/teal]div id[teal]=[/teal][green][i]"result"[/i][/green][teal]></[/teal]div[teal]>[/teal]
[teal]</[/teal]body[teal]>[/teal]
Code:
[b]var[/b] ravib21[teal]=[/teal][teal]{[/teal]
  text[teal]:[/teal] [green][i]'Content provided by myWebSite.com'[/i][/green]
[teal]}[/teal]
Or you can allow the remote site to specify a callback function :
JavaScript:
[teal]<[/teal]script type[teal]=[/teal][green][i]"text/javascript"[/i][/green][teal]>[/teal]
[b]function[/b] [COLOR=darkgoldenrod]handleThatContent[/color][teal]([/teal]what[teal])[/teal]
[teal]{[/teal]
  $[teal]([/teal][green][i]'#result'[/i][/green][teal]).[/teal]innerHTML[teal]=[/teal]what[teal].[/teal]text
[teal]}[/teal]
[teal]</[/teal]script[teal]>[/teal]
[teal]<[/teal]script type[teal]=[/teal][green][i]"text/javascript"[/i][/green] src[teal]=[/teal][green][i]"[URL unfurl="true"]http://myWebSite.com/getData.ashx?function_to_call=handleThatContent"[/URL][/i][/green][teal]></[/teal]script[teal]>[/teal]
[teal]<[/teal]body[teal]>[/teal]
[teal]<[/teal]div id[teal]=[/teal][green][i]"result"[/i][/green][teal]></[/teal]div[teal]>[/teal]
[teal]</[/teal]body[teal]>[/teal]
Code:
[COLOR=darkgoldenrod]handleThatContent[/color][teal]([/teal][teal]{[/teal]
  text[teal]:[/teal] [green][i]'Content provided by myWebSite.com'[/i][/green]
[teal]}[/teal][teal])[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top