html - How do I display a JavaScript response in proper manner? -


below javascript code calling server api:

<script type='text/javascript'>   call_juvlon_api(apikey, 'getavailablecredits', '', function(response) {      document.getelementbyid('show').innerhtml=response;   });    </script> 

when print response in html tag:

<h1 id='show'></h1> 

i'm getting results in format:

{"code":"200","status":"success:mail credit details","mail credits":"46"} 

but want result this:

<h1>code:200</h1> <h1>status:success:mail credit details</h1> <h1>mail credits:46</h1> 

i tried following, nothing displayed:

var obj=['show']   var tbl=$("<table/>").attr("id","mytable"); $("#div1").append(tbl); for(var i=0;i<obj.length;i++) {     var tr="<tr>";     var td1="<td>"+obj[i]["code"]+"</td>";     var td2="<td>"+obj[i]["status"]+"</td>";     var td3="<td>"+obj[i]["color"]+"</td></tr>";      $("#mytable").append(tr+td1+td2+td3); } 

first of you'll need 3 h1 elements, change 'show' element div this;

<div id='show'></div> 

then in javascript code, access response elements name this;

<script type='text/javascript'>    call_juvlon_api(apikey, 'getavailablecredits', '', function(response) {     var obj = json.parse(response);     for(var prop in obj) {        document.getelementbyid('show').innerhtml += '<h1>' + prop + ":" + obj[prop] + '</h1>';     } });  


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -