1

So I have an external page:

http://api.aghost.net/api/futures/index.cfm?Username=E020521102&Password=ksc0rNX&service=table&style=3&layout=chart&showGrid=0&symbols=@C@3&colorLabels=0&contractFormat=2&dateFormat=short&fontsize=large&timeFormat=m&dateFormat=m

From which I'm trying to retrieve "345'4", my code however just gives me an object, when I run '.toSource' on the object I receive the following output:

({0:{}, length:1, prevObject:{0:{location:({}), icpsignup:{0:{}, 1:{}, 2:{}, 3:{}, 4:{}, 5:{}, 6:{}, 7:{}, 8:{}, 9:{}}, jQuery1710019525210189072606:2}, context:{location:({}), icpsignup:{0:{}, 1:{}, 2:{}, 3:{}, 4:{}, 5:{}, 6:{}, 7:{}, 8:{}, 9:{}}, jQuery1710019525210189072606:2}, length:1}, context:{location:({}), icpsignup:{0:{}, 1:{}, 2:{}, 3:{}, 4:{}, 5:{}, 6:{}, 7:{}, 8:{}, 9:{}}, jQuery1710019525210189072606:2}, selector:"div.month.left span.big"})

What am I doing wrong? I feel like I'm close to a solution, but there's something I'm missing..

Below is my code:

var data = 'http://api.aghost.net/api/futures/index.cfm?Username=E020521102&Password=ksc0rNX&service=table&style=3&layout=chart&showGrid=0&symbols=@C@3&colorLabels=0&contractFormat=2&dateFormat=short&fontsize=large&timeFormat=m&dateFormat=m';
var $row1 = jQuery("div.month.left span.big"),  $row2 = jQuery("#cpuloaddynamic"), $row3 = jQuery("#meminfodynamic");

$.get("index.html", function(data){
    var $data=$(data);
    $row1.html( $data.find('tbody > tr:first-of-type > td:nth-of-type(5)').html() );
});
alert($row1.toSource());

I got my start from the following post: jquery: load values from external html and populate many local <div> fields, with one read of the html

Here's my edited code:

var data = 'http://api.aghost.net/api/futures/index.cfm?Username=E020521102&Password=ksc0rNX&service=table&style=3&layout=chart&showGrid=0&symbols=@C@3&colorLabels=0&contractFormat=2&dateFormat=short&fontsize=large&timeFormat=m&dateFormat=m';
var $row1 = jQuery("div.month.left span.big"),  $row2 = jQuery("#cpuloaddynamic"), $row3 = jQuery("#meminfodynamic");

$.get(data, function(data){
    var $data=$(data);
    $row1.html( $data.find('tbody > tr:first-of-type > td:nth-of-type(5)').html() );
    alert( $data.find('tbody > tr:first-of-type > td:nth-of-type(5)').html() );
});
Community
  • 1
  • 1
Austin Biggs
  • 179
  • 1
  • 13
  • 6
    This is really bad design: the username and password are in the URL's query string. – frenchie Oct 16 '14 at 12:43
  • What are you trying to find using `.toSource()` ? That will return the object. Did you mean `$row1.html()`? You should alert `$data.find('tbody > tr:first-of-type > td:nth-of-type(5)').html()`and see if it's right. Try using .filter() instead of .find() – Spokey Oct 16 '14 at 12:52
  • I did not create the API, I agree OAUTH should be used instead.. I was told to try .toSource(), I guess that's the wrong answer! – Austin Biggs Oct 17 '14 at 22:41
  • I've made edits to my code, but I'm hitting a wall. As @freddy mentioned, I'm having Cross Origin issues, Firebug is returning the following error message: `Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.aghost.net/api/futures/index.cfm?Username=E020521102&Password=ksc0rNX&service=table&style=3&layout=chart&showGrid=0&symbols=@C@3&colorLabels=0&contractFormat=2&dateFormat=short&fontsize=large&timeFormat=m&dateFormat=m. This can be fixed by moving the resource to the same domain or enabling CORS.` My code edits are in the original post. – Austin Biggs Oct 21 '14 at 16:26

1 Answers1

1

it seems like you are sending the request to the wrong page. The first parameter of $.get (your "index.html") is the url of the page that have to receive your request (I think it's the url you have in "data" variable). The "data" parameter in your function should have the object you expect.

However even if you fix this I don't think the code works because with jquery you can send request just to url in your domain.

freddy
  • 21
  • 2
  • 7
  • last sentence in my previous answer is why you are getting that error... You may try this http://stackoverflow.com/questions/20442628/cors-jquery-ajax-request – freddy Oct 23 '14 at 08:33