javascript - Get content from URL data by class or ID using JS -
i thinking solution night can't figure out.
i have php code download url content:
function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_connecttimeout, $timeout); $data = curl_exec($ch); curl_close($ch); homecoming $data; } $data = get_data($url);
and want content divs or whatever class name or id send variable js this:
<script> var info = <?php echo json_encode($data); ?>; alert(data); //alert shows code of downloaded url //$( ".content" ).html( info ); //this line show whole page want specific element/class </script>
how can accomplish this? let's want content of h1 tag class="productmaintitle" "data" variable in javascript ?
any tip appreciated!
depends want do.
1. send relevant fragment of html client-side
see @artm's answer.
2. send html client-side , sort out there
<script> var $data = $("<?php echo $data; ?>"); $data.find("h1.productmaintitle").appendto(".content"); </script>
assume json_encode()
unnecessary. if i'm wrong, reinsert.
if want "h1.productmaintitle" fragment less efficient (1), if want farther fragments, viable approach.
javascript php jquery css curl
No comments:
Post a Comment