Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

html5 ajax jquery

I have below codes and it was working fine. I just want to put the value inside of select html.

Thanks

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>	    
    <script type="text/javascript">
        function GetModelList() {
            var customerNo = "315217";            
            var GetModelListJSon = "http://clientaccesstest.abc.com/wcf/orders/RestService/ProService/GetModelListJSon";
            $(document).ready(function () {
                $.ajax({
                    crossDomain: true,
                    cache: false,
                    type: "GET",
                    async: false,
                    dataType: "json",
                    contentType: 'text/plain',
                    url: GetModelListJSon + encodeURIComponent("(066,315217)"),
                    success: function (data) {
                        $('#data').html(data);
                        if (data == null)
                        return;
                        resultObj = jQuery.parseJSON(data);
                        alert(resultObj.Data);
                    },
                    error: function (xhr, status, error) {
                        $('#data').html(xhr.responseText);
                        alert(xhr.responseText + " : error GetModelListJSon");
                        alert(status);
                        alert(error);
                    }
                });
            });
        }
    </script>
     <body onload="GetModelList()">
       <form action="" id="test" name="test">
         <select id="modelList" name="modelList"></select>
       </form>
     </body>

Open in new window


My question is how can I code and make the below string inside of <select></select> like I want to make it below
<select>
<option value="ModelNo">Mode No + Net Price</option>
</select>

Open in new window

?

Thanks

alert message sample below:
{"PackageKey":null,"PackageNo":1,"TotalPackages":1,"Status":"Ok","Data":"[{\"ModelNo\":\"DISCOUNT\",\"ModelName\":\"Instant Rebate \",\"NetPrice\":0.0,\"ListPrice\":0.0,\"AMD\":0.0},{\"ModelNo\":\"DISCOUNT1\",\"ModelName\":\"INSTANT REBATE ON DISPLAYS \",\"NetPrice\":0.0,\"ListPrice\":0.0,\"AMD\":0.0},{\"ModelNo\":\"DISCOUNT2\",\"ModelName\":\"INSTANT REBATE GYHM600 REBATE ONLY VALID ON ORDERS RECEIVED BY 12/31/14 \",\"NetPrice\":0.0,\"ListPrice\":0.0,\"AMD\":0.0}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsolutionWizard

ASKER

See attached. Invalid / illegal character occurred.
testing3.jpg
I fixed it by modified below

Take out ";" and remove .Data

var nestedData = jQuery.parseJSON(resultObj.Data);
                              $.each( nestedData, function(i, item) {
                                    $("#IDofSelect").append("<option value='" + item.ModelNo + "'>" + item.ModelNo + " " + item.NetPrice + "</option>");
                              });
I posted another related question.  If you have time, please helps.

https://www.experts-exchange.com/questions/28651592/wcf-asp-net-jquery-ajax-restful.html
great helper