ajax, jquery call

Question 1: I put ../RestService/QuoteService/GetModelList(066,315217) and it return data.
And I want to know how to write jquery code instead of just call on URL. Can you show me?

Question 2: the output return below: How can i bind e.g. ModelNo in html <select></select> and <asp:dropdown></asp> In code behind c#.net?

Thanks

{"PackageKey":null,"PackageNo":1,"TotalPackages":1,"Status":"Ok","Data":
"[
{\"ModelNo\":\"A20dsfasdM-SD\",\"ModelName\":\"20X FUJINON LENS 2/3\",\"NetPrice\":0.0,\"ListPrice\":2965.0,\"AMD\":2315.0},{\"ModelNo\":\"AA-FP790G\",\"ModelName\":\"12VDC POWER SUPPLY\",\"NetPrice\":0.0,\"ListPrice\":103.4,\"AMD\":107.0},

{\"ModelNo\":\"AAasdfasd0U\",\"ModelName\":\"AC ADAPTOR/BAT CHGR\",\"NetPrice\":0.0,\"ListPrice\":262.53,\"AMD\":391.0}
]"}
LVL 1
ITsolutionWizardAsked:
Who is Participating?
 
RobOwner (Aidellio)Commented:
As it looks like you're returning JSON, it should be as simple as this:

$.getJSON('../RestService/QuoteService/GetModelList(066,315217)', function(data) {
     // data now contains your JSON object you've described above
});

Open in new window


No idea about the ASP bind to select control so I"ll leave that to a .NET expert.
0
 
ITsolutionWizardAuthor Commented:
When you mentioned "// data now contains your JSON object you've described above".

I really need to know how to extract the data.
0
 
RobOwner (Aidellio)Commented:
You just use dot notation:

E.g.
data.PackageKey
Or
data.Data; //contains your array

Does they make sense?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ITsolutionWizardAuthor Commented:
no...i am new here. so please show me in codes.
0
 
RobOwner (Aidellio)Commented:
in your webpage you have a <select id='mylist'></select>

$.getJSON('../RestService/QuoteService/GetModelList(066,315217)', function(data) {
     // data now contains your JSON object you've described above
    if (data.Status === "Ok") {
        $.each(data.Data, function(i,el) {
            $("#mylist").append("<option value='"+el.ModelNo+"'>"+el.ModelName+"</option>");        
}
});

Open in new window

0
 
ITsolutionWizardAuthor Commented:
Well, I found out your code missing ")" and I added it is still not working. I verify the web service is fine.
Below is the code

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>      
    <script language="javascript" type="text/javascript">
        $.getJSON('../RestService/QuoteService/GetModelList(066,315217)',    
    function(data)
    {
         // data now contains your JSON object you've described above
        if (data.Status == "Ok") {
             $.each
            (
            data.Data, function(i,el)
            {
            $("#mylist").append("<option value='" +el.ModelNo + "'>" + el.ModelName + "</option>");            
             }
             )
        }
    }    
    );
    </script>
0
 
RobOwner (Aidellio)Commented:
I'll get a demo working for you soon
0
 
ITsolutionWizardAuthor Commented:
Thanks
0
 
RobOwner (Aidellio)Commented:
http://jsbin.com/lecini/1/edit?html,js,output which uses http://jsbin.com/roquge/1.js as sample data

$(function() {
  var url = '../RestService/QuoteService/GetModelList(066,315217)';
  url = 'http://jsbin.com/roquge/1.js'; // this is just for testing and you should comment out this line for your testing
  $.getJSON(url, function(data) {
    // data now contains your JSON object you've described above
    if (data.Status === "Ok") {
      $.each(data.Data, function(i,el) {
        $("#mylist").append("<option value='"+el.ModelNo+"'>"+el.ModelName+"</option>");        
      });
    }
  });
});

Open in new window


html
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<select name="mylist" id="mylist"></select>
</body>
</html>

Open in new window

0
 
ITsolutionWizardAuthor Commented:
Why using === ok? Should it be == ?
0
 
RobOwner (Aidellio)Commented:
== you leave it up to JavaScript to determine if each side is equal. Eg 2 == "2" well more often than not return true though one is a number and one is a string.
=== ensures they are the same value as well as type. Eg both must be a string or both must be a number etc
0
 
ITsolutionWizardAuthor Commented:
I see thank
0
 
RobOwner (Aidellio)Commented:
Did the demo work for you? We're you able to adapt the code?
0
 
ITsolutionWizardAuthor Commented:
I have to try later. But for some reasons the status is undefined when I tried earlier.
0
 
RobOwner (Aidellio)Commented:
No problem just post when you've got an update. I'm still monitoring :)
0
 
ITsolutionWizardAuthor Commented:
still not working.

For some reason, my web service return status 'undefined' however, when I load the web service on url with input parameter. It is working.

Now I do not why.  My Web service has no issue at all.
0
 
RobOwner (Aidellio)Commented:
Ok back to basics then:

Try $.get('../RestService/QuoteService/GetModelList(066,315217)', function(data) {
console.log(data);
});

Also please post the full JavaScript code you're using
0
 
ITsolutionWizardAuthor Commented:
it show null.

And if I want to test below:

how to  load data from ( '../RestService/QuoteService/GetModelList(066,315217)';
)

and put it into of your .js file.

This way at least I can try test it out.

Currently, if I open  '../RestService/QuoteService/GetModelList(066,315217)' on the browser, I can see the information list it
0
 
RobOwner (Aidellio)Commented:
Maybe you're just missing the jQuery wrapper:

$(function() {
$.get('../RestService/QuoteService/GetModelList(066,315217)', function(data) {
console.log(data);
});
});
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.