0

How do I use jQuery's $.get to collect the text shown on the page? The link I provided has a page with the text 'true'. How do I alert the text of the page? This is my code, thanks

$.get( "http://api.roblox.com/ownership/hasasset?assetId=52454955&userId=1", function( data ) {
  var x = $( "body" ).text( data );
  alert( x );
});
Sam
  • 41
  • 1
  • 7

1 Answers1

0

The callback parameter has the page contents so:

$.get( "http://api.roblox.com/ownership/hasasset?assetId=52454955&userId=1", function( data ) {
  alert( data );
});
omma2289
  • 54,161
  • 8
  • 64
  • 68
  • XMLHttpRequest cannot load http://api.roblox.com/ownership/hasasset?assetId=52454955&userId=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.roblox.com' is therefore not allowed access. – Sam Jun 10 '14 at 18:21
  • That's the error I get when doing this on any page. When I do it on the actual website, I get "TypeError: undefined is not a function" – Sam Jun 10 '14 at 18:22
  • `TypeError: undefined is not a function` probably means jQuery is not loaded correctly. The other error means the page you're requesting doesn't allow cross domain requests. – omma2289 Jun 10 '14 at 18:23
  • 1
    @Sam You may find **[this answer](http://stackoverflow.com/a/10143166/2311559)** useful. – agrm Jun 10 '14 at 18:25