Ashwini Khare
Ashwini Khare

Reputation: 1675

jQuery parse huge response fail

I'm working on an application that sends request to a url and parses the table present on the html in response using jQuery. While this seems to work quite nicely when the amount of html code being returned is reasonable, it somehow fails with big datsets.

The issue starts when

   $.get(url, function(response){
     $(response).find('table');
   })

returns an emtpy search result despite having a table in the response string.However the same piece code works just fine when tables are small (approximately 1000 columns)

Any idea how can this issue be tackled?

For testing purposes, I'm working with this dataset as of now, http://socr.ucla.edu/docs/resources/SOCR_Data/SOCR_Data_Dinov_020108_HeightsWeights.html

Any alternative suggestions to make this process a bit faster?

Upvotes: 1

Views: 110

Answers (1)

Pointy
Pointy

Reputation: 413737

Try this:

$.get(url, function(response){
  var $response = $(response);
  var $table = $response.is('table') ? $response : $response.find('table');
  // ...

})

If the response HTML/XML is a <table>, then find() won't find it. It only looks at descendants of the element you start from. The code above checks to see whether you've already got the <table>.

Upvotes: 1

Related Questions