-1

How to convert content of web page to json file ? Like I pass the url of page n it got converted to json file. Web page only contains json string.

Bhoomi Akhani
  • 25
  • 1
  • 5

1 Answers1

0

Also you can do it with ajax

 <script type="text/javascript">
    function loadJSONDoc(url) {
        var xmlhttp;

        if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
        } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }

     xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 ) {
            if(xmlhttp.status == 200){
                document.getElementById("myBody").innerHTML = xmlhttp.responseText;
                //if your response text is JSON object
               document.getElementById("myBody").innerHTML = JSON.stringify(xmlhttp.responseText);
            }
         else if(xmlhttp.status == 400) {
            alert('There was an error 400')
         }
         else {
           alert('something else other than 200 was returned')
         }
       }
    }

   xmlhttp.open("GET", url, true);
   xmlhttp.send();
   }
 loadJSONDoc("your_url")
</script>

OrginalAjaxMethotHere

Community
  • 1
  • 1
Mehmet Otkun
  • 1,374
  • 9
  • 22