2

I have the following. HTML

 <div class="frmInput">
                        <select id="registrationTypeDropDown" class="select">
                            
                        </select>
                    </div>

Javascript

fetch('../svc/RegistrationForm.asmx/GetRegistrationType', {
    method: 'GET',
    credentials: 'same-origin',
    headers: {
        'Content-Type': 'application/json'
    }
}).then((response) => {
    types = response.json();
    
    for (const [ID, Name] of Object.entries(types)) {
        console.log(ID, Name);
        options += '<option value="' + ID + '" text="' + Name + '" />';
    }
    $('#registrationTypeDropDown').append(options);
  });

I've tried different ways of getting my results and nothing is working. When I run it it doesn't even hit my for loop. I'd appreciate it if someone can point out a better way of doing this or what I'm doing wrong.

enter image description here

2
  • 1
    Are you getting a response? Commented Aug 11, 2020 at 21:09
  • Yes I am getting a response. Commented Aug 11, 2020 at 21:14

1 Answer 1

1

You are actually assigning Promise to the types variable try this. Also see using fetch api

fetch('../svc/RegistrationForm.asmx/GetRegistrationType', {
  method: 'GET',
  credentials: 'same-origin',
  headers: {
    'Content-Type': 'application/json'
  }
}).then(response => response.json()). // you are missing this line
then((response) => {
  types = response;

  for (const [ID, Name] of Object.entries(types)) {
    console.log(ID, Name);
    options += '<option value="' + ID + '" text="' + Name + '" />';
  }
  $('#registrationTypeDropDown').append(options);
});

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you that fixed the the issue getting values in the variable types but the Name constant in the for loop is defined as the array. How do I get the values from it.
Can you post the response ??
I just posted the image from chrome dev tools in the original post. You see d is the ID const and Name is the Array.
its tough to figure out like this can you post the data ,it would be verry easier
idRegistrationType registrationType 23 Reseller 24 Guest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.