从JSON获取信息并使用JavaScript保存在SQL Server中

时间:2018-10-23 14:41:34

标签: javascript json sql-server rest server

从JSON获取信息并使用JavaScript保存在SQL Server中

我有这段代码,该代码返回我想要的信息并显示在页面上。

现在我需要将此信息保存在SQL Server数据库中,怎么可能?

这对我来说非常困难,因为我以前从未使用过API,JSON或JavaScript

<!DOCTYPE html>
<html>
<head>
    <style>     
        .bodyFrame {
            margin: 40px;
        }

        .headerLabel {
            font-weight: bold;
        }

    </style>        
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head> 
<body>
    <div class="bodyFrame">
        <h2 style="text-align:center;">WIDS JSON Retrieval Example</h2>

        <button type="button" onclick="makeServiceCall()">Retrieve JSON Data</button>
        <br /><br />

        <label class="headerLabel">Programs</label>
        <ul id="programUL"></ul>
    <div>       
    <script>        
        function makeServiceCall() {                    
            var url = "http://widsservicedev.yaharasoftware.com/WidsService/JSON/GetPortagePrograms/?apikey=104043F0-9C24-4957-879D-046868973CC4&callback";

            $.getJSON(url, function (data) {
                //var myArray = [];
                //myArray[0] = data;
                parseProgramData(data, url);
            });                 
        }

        function parseProgramData(jsonData, url) {      

            $("#dataHeader").empty();
            $("#dataHeader").append('<b>' + url + '</b>');

            var programUL = document.getElementById("programUL");       

            for (var pgmIndex = 0; pgmIndex < jsonData.Programs.length; pgmIndex++) {                   
                var pgmLi = document.createElement("li");
                var program = jsonData.Programs[pgmIndex];
                var programInfoRevision = program.ProgramInfoRevisions[0];
                var numberTitle = programInfoRevision.ProgramNumber + " " + programInfoRevision.ProgramTitle;
                pgmLi.appendChild(document.createTextNode(numberTitle));
                programUL.appendChild(pgmLi);                   

                var linebreak = document.createElement("br");
                pgmLi.appendChild(linebreak);

                var poLabel = document.createElement("label");
                poLabel.appendChild(document.createTextNode("Program Outcomes"));
                poLabel.classList.add("headerLabel");                   
                pgmLi.appendChild(poLabel);                 

                var pgmOutcomeUL = document.createElement("UL");
                pgmLi.appendChild(pgmOutcomeUL);

                for (var poIndex = 0; poIndex < program.ProgramOutcomes.length; poIndex++) {                    
                    var poLi = document.createElement("li");
                    poLi.appendChild(document.createTextNode(program.ProgramOutcomes[poIndex].Description));
                    pgmOutcomeUL.appendChild(poLi);
                }                                        
            }               
        }
    </script>           
</body> 
<footer>        
</footer>       
</html>

0 个答案:

没有答案