How to get JSON data from an IP address only using JavaScript -


i have little doubt still json. know how json data local file. want same data network ip address.

here ip address

  1. i'm sitting on - 10.1.128.103
  2. default gateway - 10.1.128.1
  3. json data passer - 10.1.128.106

here data.json file inside

{"jsonprojectidresult": [{"_capacity": 15,"_description": "meeting room","_dev_default_view": 3,"_deviceid": 1,"_devicename": "mobitech","_devicetypeid": 1,"_projectid": 1,"_roomid": 2,"_roomname": "room2","_room_admin_mail": null},{"_capacity": 2,"_description": "meeting rooms","_dev_default_view": 5,"_deviceid": 2,"_devicename": "mobiteches","_devicetypeid": 4,"_projectid": 2,"_roomid": 2,"_roomname": "room4","_room_admin_mail": null}]} 

here html codes simple javascript simple code, if did wrong please let me know guys.

<!doctype html> <html lang="en"> <head>   <meta charset="utf-8">   <title>javascript json data</title>  </head> <body>  <h1>my home page</h1>  <div id="results">     <!-- display jason data --> </div>  <script>      var resultdiv = document.getelementbyid("results");      //var newsurl = "http://10.1.128.106/jsondohabacktotemplate/getprojectidbymac.svc/mac/10:95:84:11:00:05";      var newsurl = "http://localhost:81/testjs/data.json";      var e;      if (window.xmlhttprequest) {         // code ie7+, firefox, chrome, opera, safari         e = new xmlhttprequest();     } else {         // code ie6, ie5         e = new activexobject("microsoft.xmlhttp");     }      e.onreadystatechange = function() {          var html = " ";          if (e.readystate == 4 && e.status == 200) {             response = json.parse(e.responsetext);              if(typeof(e.responsetext)==="string") {                 d = e.responsetext;             } else {                 if (typeof(e.responsexml)==="object") {                     d = e.responsexml;                 };             }              var mydata = response['jsonprojectidresult'];              //loop             var html = "<ul>";             var = 0;             for(var prop in mydata[a]) {                 if(mydata[a].hasownproperty(prop))                 html += "<li>" + prop + " = " + mydata[a][prop] + "</li>";             }              resultdiv.innerhtml = html;         }     };      e.open("get", newsurl, true);     e.send();  </script>  </body> </html> 

this final question. code totally working when used var newsurl = "http://localhost:81/testjs/data.json"; want use in var newsurl = "http://10.1.128.106/jsondohabacktotemplate/getprojectidbymac.svc/mac/10:95:84:11:00:05";

how use javascript this?

finally reached target expert in stackoverflow.com. i'm thanking me resolve problem.

finally, give answer other learners keep in going.

when going use cors read click here. guid.

when going use cors. need use code in server send data application.

header('content-type: text/html'); header('access-control-allow-origin: *'); 

i think someone.

thanks everyone


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -