Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:36:41+00:00 2026-06-08T22:36:41+00:00

I have two forms (‘table’ and ‘fields’). The ‘fields’ form is supposed to pre-populate

  • 0

I have two forms (‘table’ and ‘fields’). The ‘fields’ form is supposed to pre-populate with options depending on the choice made in ‘table’, by making an Ajax request.
The data is returning perfectly and actually prepopulates the second form (like it should) if I pass a cut-and-paste example of some returned data to a local variable (see commented line).But for some reason it won’t work on the returned object??
Any advice would be appreciated as I am very new to JavaScript and am probably missing something blatantly obvious! I am using the following code:

$(document).ready(function() {
$('select#table').change(function(){
$.getJSON("/ajax_get",{id: $(this).val(), ajax: 'true'}, function(data) {
//var data = [{"optionValue":"address", "optionDisplay": "address"},{"optionValue":"latitude", "optionDisplay": "latitude"},{"optionValue":"longitude", "optionDisplay": "longitude"},];
  var $persons = $('#fields').empty();
  $.each(data, function() {
    $persons.append("<option value=" + this.optionValue + ">" + this.optionDisplay + "</option>");
  });
});
});
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:36:43+00:00Added an answer on June 8, 2026 at 10:36 pm

    Here’s a simplified version of your call that should help you figure it out quickly:

    $.getJSON("/ajax_get",{id: $(this).val(), ajax: 'true'}, function(data) {
      try { 
           typeof(data.somethingYouExpect);
           /* do your on success work here */
      } catch (e) {
         alert('There is a good chance the response was not JSON');
      }
    });
    

    Even when using the regular jQuery $.ajax call, it’s important to check to be sure the returned response is in the form you expect. This is as simple as setting a variable like success in your response as true. If you did that, the above example becomes something like this:

    var jqxhr = $.getJSON("/ajax_get",{id: $(this).val(), ajax: 'true'}, function(data) {
      try { 
           typeof(data.success); // Will throw if success is not present
           if (success == true) {
                 /* handle success */
           } else {
                 /* handle a request that worked, but the server said no */
           }
      } catch (e) {
         /* The actual HTTP request worked, but rubbish was returned */
         alert('There is a good chance the response was not JSON');
         console.dir(jqxhr.textResponse);
      }
    });
    

    Here, we remember the object returned by the $.getJSON call (which is just a shortcut to $.ajax), which allows us to view the actual response sent by the server. I’m willing to bet it’s a 404, parser error or something of that sort.

    For most things, I usually just use $.ajax mostly out of personal preference, where the error callback passes the xhr object to a common function to examine (did the request return 200? etc). If something explodes, I know exactly what went wrong by briefly looking at the console and can disable debug output in one place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have two forms in my project: MainWindow and Options Form (OptForm; QWidget
I have two forms. The first form is the mainForm, this never goes anywhere.
I have two forms in one view updating the User Profile. One Form is
I have two forms, first form contains the textbox and second form contains a
I have two forms using a ListView component. In the first form it works
I have two forms, one is the main form and the other is an
I have two forms on one page: a results form and a search form.
I have two forms in a page <form id=form1> </form> <form id=form2> </form> in
I have two forms = Form1.CS and SMS.CS on the first form (Form1) i've
I have two forms. One is a parent form with a button and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.