javascript - I'm trying to get IP address value printed into 4 box's on some Html web page -


i have string "." in address trying use , java script string tokenizer , slip each address each box

source c file passes values when requested html page (ipcfg/ipcfg_get)

/* * { "ipv4": { *  "addr": "192.168.1.1", *  "mask": "255.255.255.0", *  "gw": "192.168.1.1" } * } */ cp = s; cp += sprintf(cp, "{ \"ipv4\": {"); cp += sprintf(cp, "\"addr\": \"%d.%d.%d.%d\",",         ip4_addr1(ipv4_addr), ip4_addr2(ipv4_addr),         ip4_addr3(ipv4_addr), ip4_addr4(ipv4_addr)); cp += sprintf(cp, "\"mask\": \"%d.%d.%d.%d\",",         ip4_addr1(ipv4_mask), ip4_addr2(ipv4_mask),         ip4_addr3(ipv4_mask), ip4_addr4(ipv4_mask)); cp += sprintf(cp, "\"gw\": \"%d.%d.%d.%d\"",         ip4_addr1(gw_addr), ip4_addr2(gw_addr),         ip4_addr3(gw_addr), ip4_addr4(gw_addr)); cp += sprintf(cp, "}}");    

html program values c file calling function , no not brackets or closing arguments.

<script>       function ipcfg_get ()  {         $.ajax({             type: 'get',             url: '/ipcfg/ipcfg_get.cgi',             datatype: 'json',             success: function(data) {                 var s = 'addr: ' + data.ipv4.addr;                 s += ', mask: '+ data.ipv4.mask;                 s += ', gw: ' + data.ipv4.gw;             },        }); }  $(function() {     $('#btnreset').on('click', ipcfg_get); $('#btnapply').on('click', ipcfg_set); }); </script> 

in success function instead of doing string operations on s. (j s o n after stands javascriptobjectnotation treat variables js objects , shall fine.)

var s={};
s.addr=data.ipv4.addr;
s.mask=data.ipv4.mask;
s.gw=data.ipv4.gw;
//do s after put div
alert(s);


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -