javascript - Is there a way to use jquery map text into json from a string? -


first of all, asking question due broken api of petfinder. working on rabbit rescue app (its web interface) , need of petfinder's search results. fix public api soon, meanwhile using php load html content of search results , turn json front end display.

the current method use load page invisible div tag , use jquery selector map content. not efficient because load of original script , css files petfinder. able manipulate string directly.

here of examples:

original code structure:

<html>   <head>     ...   </head>   <body style="background:#ffffff">     <style type="text/css">       ...     </style>     <body bgcolor="#ffffff" text="#000000" >       <table>         ...           ...             <tr class = "pfrow2">               <td><a href="//www.petfinder.com/petdetail/30773115" class="pflink" target="_blank">                 billie bunny                 </a>               </td>               <td>                 rabbit               </td>               <td>                 dutch               </td>               <td>                 adult               </td>               <td>                 small               </td>               <td class='legacy'>                 <a href="//www.petfinder.com/petdetail/30773115" target="_blank">                 <img src="//drpem3xzef3kf.cloudfront.net/photos/pets/30773115/1/?bust=1415669533&width=130" class="img pets" border="0">                 </a>               </td>             </tr>             <tr class="pfrow1">               <td><a href="//www.petfinder.com/petdetail/30891970" class="pflink" target="_blank">                 barnabas bunny                 </a>               </td>               <td>                 rabbit               </td>               <td>                 himalayan, new zealand               </td>               <td>                 young               </td>               <td>                 medium               </td>               <td class='legacy'>                 <a href="//www.petfinder.com/petdetail/30891970" target="_blank">                 <img src="//drpem3xzef3kf.cloudfront.net/photos/pets/30891970/3/?bust=1421966387&width=130" class="img pets" border="0">                 </a>               </td>             </tr>             ... 

as can see information need within tr class = "pfrow2" , tr class = "pfrow1". wonder if there way similar grab $(".pfrow2").map(function(){}) if class within string.

alternatively, can cut out dom before pfrow2 , after pfrow1?

btw current json output (note change width of image because want use larger thumbnails).

[{   name: "billie bunny",   type: "dutch",   age: "adult",   size: "small",   thumb: "//drpem3xzef3kf.cloudfront.net/photos/pets/30773115/1/?bust=1415669533&width=300",   link: "//www.petfinder.com/petdetail/30773115" },{   name: "barnabas bunny",   type: "himalayan, new zealand",   age: "young",   size: "medium",   thumb: "//drpem3xzef3kf.cloudfront.net/photos/pets/30891970/3/?bust=1421966387&width=300",   link: "//www.petfinder.com/petdetail/30891970" }] 

i don't know how make string directly able cut rows out you. assuming data result returned php.

var json = data.substring(data.indexof('<tr class = "pfrow2">') - 21);     json = json.substring(0,json.lastindexof('</td>') + 5);     function widthchange() {       if (json.indexof('&width=130') != -1) {         json = json.replace('&width=130','&width=300');         widthchange();       } else {         console.log(json);         // here can inset json dom       }     }     widthchange(); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -