简体   繁体   English

jQuery解析巨大的响应失败

[英]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. 我正在开发一个应用程序,该应用程序将请求发送到url并使用jQuery解析html中存在的表。 While this seems to work quite nicely when the amount of html code being returned is reasonable, it somehow fails with big datsets. 当返回的html代码数量合理时,这似乎很好用,但由于大数据集而以某种方式失败了。

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) 尽管响应字符串中有表格,但仍返回空的搜索结果。但是,当表格较小(大约1000列)时,相同的片段代码也可以正常工作

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 为了进行测试,到目前为止,我正在使用此数据集, http://socr.ucla.edu/docs/resources/SOCR_Data/SOCR_Data_Dinov_020108_HeightsWeights.html

Any alternative suggestions to make this process a bit faster? 还有其他建议可以使此过程更快一些吗?

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. 如果响应HTML / XML是<table> ,则find()找不到它。 It only looks at descendants of the element you start from. 它仅查看您从其开始的元素的后代。 The code above checks to see whether you've already got the <table> . 上面的代码检查是否已经有了<table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM