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

  • Home
  • SEARCH
  • 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 8560783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:21:22+00:00 2026-06-11T16:21:22+00:00

Initially when the page loads, ajax populates a selectmenu. When I enter new patient

  • 0

Initially when the page loads, ajax populates a selectmenu. When I enter new patient information it is added to the database but the patient selectmenu does not get append to/refresh with that new patient being selected.

I was hoping someone could help me with what Im doing wrong.

Ajax call

$('#newpatient').click(function() {
    var patientadd = $('#patientaddform').serializeArray();
    $.ajax({
        url: 'patientadd.php',
        type: "POST",
        data: patientadd,
        dataType: 'json',
        success: function(data) {
            var html = '';
            var len = data.length;
            for (var i = 0; i < len; i++) {
                html += '<option value="' + data[i].patient_id + '">' + data[i].patient_firstname + ' ' + data[i].patient_lastname + '</option>';
            }
            $('#patientselect').append(html);
        },
        complete: function() {
            $('#patientselect').selectmenu('refresh', true);
        }
    });
});​

patientadd.php

if (empty($_POST) === false) {
    $update_data = array('company_id' = > $_POST['company_id'], 'addpatient_firstname' = > $_POST['addpatient_firstname'], 'addpatient_lastname' = > $_POST['addpatient_lastname'], 'addpatient_dob' = > $_POST['addpatient_dob'], 'patient_added' = > $_POST['patient_added']);


    $required_fields = array('company_id', 'addpatient_firstname', 'addpatient_lastname', 'addpatient_dob', 'patient_added');
    foreach($update_data as $key = > $value) {
        if (empty($value) && in_array($key, $required_fields) === true) {
            $errors[] = 'Fields marked with an asterisk are required';
            break 1;
        }
    }
}

if (empty($_POST) === false && empty($errors) === true) {

    $company_id = $_POST['company_id'];
    $patient_id = $_POST['addpatient_id'];
    $first_name = $_POST['addpatient_firstname'];
    $last_name = $_POST['addpatient_lastname'];
    $dob = $_POST['addpatient_dob'];
    $updated = $_POST['patient_added'];


    $update = array();
    array_walk($update_data, 'array_sanitize');

    foreach($update_data as $field = > $data) {
        $update[] = '`'.$field.'` = \''.$data.'\'';
    }

    mysql_query("INSERT INTO `lab`.`patients` (`company_id`,  `patient_id`, `patient_firstname`, `patient_lastname`, `patient_dob`, `patient_added`) VALUES ('$company_id', NULL, '$first_name', '$last_name', '$dob', '$updated')");
    $patient_id = mysql_insert_id(); /*echo '<strong>' . $patient_id . ' ' . $first_name . ' ' . $last_name . '</strong> has been added!';*/
}

$data = array('patient_id' = > $patient_id, 'patient_firstname' = > $first_name, 'patient_lastname' = > $last_name);
echo json_encode($data);
  • 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-11T16:21:23+00:00Added an answer on June 11, 2026 at 4:21 pm

    Move you code from complete to the success function.

    $('#newpatient').click(function() {
        var patientadd = $('#patientaddform').serializeArray();
        $.ajax({
            url: 'patientadd.php',
            type: "POST",
            data: patientadd,
            dataType: 'json',
            success: function(data) {
                var html = '';
                var len = data.length;
                for (var i = 0; i < len; i++) {
                    html += '<option value="' + data[i].patient_id + '">' + data[i].patient_firstname + ' ' + data[i].patient_lastname + '</option>';
                }
                $('#patientselect').append(html);
                $('#patientselect').selectmenu('refresh', true);
            },
            complete: function() {
                //$('#patientselect').selectmenu('refresh', true);
            }
        });
    });​
    

    Ajax executes is asynchronous. The success method only executes ones the request returns. However, ones success is triggered, so is complete. This means you end up in a race-condition in which complete executes before success is finished executing. Complete does not wait for success to finish. success and complete pretty much execute simultaneously.

    To ensure your refresh call includes the new data execute refresh within the success following the append.

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

Sidebar

Related Questions

I am working on a GridView in Asp.Net. When initially a the Page Loads,
I have a page that has 4 tables. Initially when the page is loaded,
Initially i was planning to use master page for every page in my application.
I have a page with a list of items initially loaded from a include_once('show_calendarV2.php');
I have a page where I am loading bunch of images initially when the
I have an iframe on a page that I need to initially have a
I am using jcarousel on a page in 3 different sections. I initially show
I have some link elements which are dynamically added and hidden from the page.
I currently have a page that contains an unordered list. That list is initially
So I'm new to Ajax. I have an ASP.NET wizard panel wrapped in an

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.