javascript - How to create hyperlinks inside div from within ajax response? -
i create 1 hyperlink inside mydiv each maxnumid(ajax response) recive ajax this(each time click loadmore button 1 maxnumid api , want use value inside hyperlink , display hyperlink in mydiv):
<a href="./process.php?maxnumid=123451">123451</a> <a href="./process.php?maxnumid=123452">123452</a> <a href="./process.php?maxnumid=123453">123453</a> could 1 show me how can done?
<script> var maxnumid = null; function callapi() { $.ajax({ type: "get", datatype: "jsonp", cache: false, url: "https://api.somesite.com/......"), success: function(data) { maxnumid = data.pagination.next_num_id; if (maxnumid === undefined || maxnumid === null) { alert('end!'); } else { //here want used maxnumid , create hyperlink each maxnumid //and place in mydiv $('#mydiv').append(maxnumid); } } }); } </script> <body> <br> <center> <div id="mydiv"></div> <button id="mango" onclick="callapi()">load more</button> </html>
else { var na = $('<a/>'); na.attr('href', "./process.php?maxnumid=" + maxnumid); na.text(maxnumid); $('#mydiv').append(na); } edit:
if want have each link in separate there different ways achieve that. here two:
append linebreak after each link:
$('#mydiv').append(na).append($('<br/>'));make links
blockelements (and possibly give them class)://... na.addclass('mylink'); $('#mydiv').append(na);and in css:
.mylink {display: block;}
Comments
Post a Comment